Discord.py Discord Python-如何使bot在if message.content下接收消息

Discord.py Discord Python-如何使bot在if message.content下接收消息,discord.py,Discord.py,对不起,我的英语不好,但我需要帮助 我是否可以使bot在if message.content下接收消息 async def on_message(message): message_loop = message.content if message.content == "!run": await message.delete() random_difficult = ['{}{}{}{}{}{}'.format(random.

对不起,我的英语不好,但我需要帮助 我是否可以使bot在if message.content下接收消息

async def on_message(message):
    message_loop = message.content
    if message.content == "!run":
        await message.delete()
        random_difficult = ['{}{}{}{}{}{}'.format(random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character)),
                            '{}{}{}{}{}'.format(random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character)),
                            '{}{}{}{}{}{}{}'.format(random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character)),]

        choice_difficult = random.choice(random_difficult).lower()
        await message.channel.send(choice_difficult)
        game_embed= discord.Embed(
        colour = discord.Colour.dark_blue())
        game_embed.set_image(url='https://fakeimg.pl/350x200/?text={}'.format(choice_difficult))
        game_embed.set_author(name='... Arcade Game',icon_url='http://mqt-web.tk/image/RBS-Logo.png')
        game_embed.set_footer(text='Power by ....', icon_url='http://icons.iconarchive.com/icons/paomedia/small-n-flat/1024/sign-check-icon.png')
        game_embed.add_field(name='TEXT', value='TEXT', inline=True)
        game_embed.add_field(name='TIME LIMITE', value='20 Sec', inline=True)
        message_bot = await message.channel.send(embed=game_embed)
     
        start = True
        count = 0
        while start == True:
            count = count + 1
            await asyncio.sleep(1)
            if message.content == choice_difficult:
                #some code
            print(count)

我不知道该怎么做

你可以使用
等待
来完成这个。因为它在消息上的
事件中不起作用。您应该在如下命令中使用它:

@client.commnad()
async def run(ctx):
        await message.delete()
        random_difficult = ['{}{}{}{}{}{}'.format(random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character)),
                            '{}{}{}{}{}'.format(random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character)),
                            '{}{}{}{}{}{}{}'.format(random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character)),]

        choice_difficult = random.choice(random_difficult).lower()
        await message.channel.send(choice_difficult)
        game_embed= discord.Embed(
        colour = discord.Colour.dark_blue())
        game_embed.set_image(url='https://fakeimg.pl/350x200/?text={}'.format(choice_difficult))
        game_embed.set_author(name='RobuxshopTH Arcade Game',icon_url='http://mqt-web.tk/image/RBS-Logo.png')
        game_embed.set_footer(text='Power by ....', icon_url='http://icons.iconarchive.com/icons/paomedia/small-n-flat/1024/sign-check-icon.png')
        game_embed.add_field(name='TEXT', value='TEXT', inline=True)
        game_embed.add_field(name='TIME LIMITE', value='20 Sec', inline=True)
        message_bot = await message.channel.send(embed=game_embed)
     
        start = True
        count = 0
        while start == True:
            count = count + 1
            await asyncio.sleep(1)
            await client.wait_for('message', check=choice_difficult, timeout=20)
def check():
    return choice_difficult
await client.wait_for('message', check=check, timeout=20)
您可以删除
timeout
参数,但如果您这样做,并且用户从未像
choice\u困难
那样响应,则会带来问题

编辑

您应该在
check
参数中设置如下函数:

@client.commnad()
async def run(ctx):
        await message.delete()
        random_difficult = ['{}{}{}{}{}{}'.format(random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character)),
                            '{}{}{}{}{}'.format(random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character)),
                            '{}{}{}{}{}{}{}'.format(random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character)),]

        choice_difficult = random.choice(random_difficult).lower()
        await message.channel.send(choice_difficult)
        game_embed= discord.Embed(
        colour = discord.Colour.dark_blue())
        game_embed.set_image(url='https://fakeimg.pl/350x200/?text={}'.format(choice_difficult))
        game_embed.set_author(name='RobuxshopTH Arcade Game',icon_url='http://mqt-web.tk/image/RBS-Logo.png')
        game_embed.set_footer(text='Power by ....', icon_url='http://icons.iconarchive.com/icons/paomedia/small-n-flat/1024/sign-check-icon.png')
        game_embed.add_field(name='TEXT', value='TEXT', inline=True)
        game_embed.add_field(name='TIME LIMITE', value='20 Sec', inline=True)
        message_bot = await message.channel.send(embed=game_embed)
     
        start = True
        count = 0
        while start == True:
            count = count + 1
            await asyncio.sleep(1)
            await client.wait_for('message', check=choice_difficult, timeout=20)
def check():
    return choice_difficult
await client.wait_for('message', check=check, timeout=20)
因此,新的代码是:

@client.commnad()
async def run(ctx):
        await message.delete()
        random_difficult = ['{}{}{}{}{}{}'.format(random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character)),
                            '{}{}{}{}{}'.format(random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character)),
                            '{}{}{}{}{}{}{}'.format(random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character),random.choice(character)),]

        choice_difficult = random.choice(random_difficult).lower()
        await message.channel.send(choice_difficult)
        game_embed= discord.Embed(
        colour = discord.Colour.dark_blue())
        game_embed.set_image(url='https://fakeimg.pl/350x200/?text={}'.format(choice_difficult))
        game_embed.set_author(name='RobuxshopTH Arcade Game',icon_url='http://mqt-web.tk/image/RBS-Logo.png')
        game_embed.set_footer(text='Power by ....', icon_url='http://icons.iconarchive.com/icons/paomedia/small-n-flat/1024/sign-check-icon.png')
        game_embed.add_field(name='TEXT', value='TEXT', inline=True)
        game_embed.add_field(name='TIME LIMITE', value='20 Sec', inline=True)
        message_bot = await message.channel.send(embed=game_embed)
        def check():
            return choice_difficult
        start = True
        count = 0
        while start == True:
            count = count + 1
            await asyncio.sleep(1)
            await client.wait_for('message', check=check, timeout=20)

如果message.content==“stop”:
是您要找的,我相信谢谢您的回复,但它不起作用哪里定义了
字符
?对不起,我编辑了一些代码。现在没有错误,但当我键入discord channelThx时没有任何错误,但它不起作用我得到了这个错误
TypeError:“str”对象不可调用
对不起,我错了,我编辑了答案,所以这必须起作用。我尝试
等待客户端。等待('message',check=check(),timeout=20)
并得到这个错误:这个链接帮助我: