首页 > 解决方案 > Discord Bot 在不应该的情况下随机发送多次命令

问题描述

我创建的不和谐机器人应该在有人打招呼时被激活,但是当这种情况发生时,会发送多个输出。我知道 discord.py 所以这可能是一个愚蠢的问题,但是很容易解决,但不确定如何做到这一点:


import discord


bot = discord.Client()


@bot.event
async def on_ready():

    guild_count = 0


    for guild in bot.guilds:

        print(f"- {guild.id} (name: {guild.name})")


        guild_count = guild_count + 1


    print("SampleDiscordBot is in " + str(guild_count) + " guilds.")


@bot.event
async def on_message(message):

    if message.content == "hello":

        await message.channel.send("hey")

    if message.content == "what is your wisdom o' truth bot":
        await message.channel.send("Stupid, this is!")


bot.run('KEY')

标签: pythonpython-3.xdiscorddiscord.py

解决方案


推荐阅读