当我回答“是”时什么都没有发生?

时间:2021-04-03 17:51:19

标签: discord discord.py warnings

这是我目前的代码:

    @commands.command()
    async def destroy(self, ctx):
        def check(m):
            em = discord.Embed()
            return em.author == ctx.author and m.channel == ctx.channl

        await ctx.message.delete()
        em = discord.Embed(color=15859772, title = ":rotating_light: WARNING WARNING :rotating_light:", description=f"{ctx.author.mention} Are you sure you want to run this command? yes/no")
        await ctx.send(embed=em)
        # for user input
        response = await self.client.wait_for('message', check=check)
    
        if response.content.lower() == 'yes':
            await ctx.send("Done")
        else:
            await ctx.send("Canceled")

不知道出了什么问题。但是如果我回复 yes 什么都不会发送并且我没有收到错误?

1 个答案:

答案 0 :(得分:2)

你的 check 对我来说毫无意义。你为什么要在那里放一个嵌入?

试试这个:

        def check(m):
            return m.author == ctx.author and m.channel == ctx.message.channel

这将检查命令的作者是否在正确的频道中响应。

正如评论中提到的,以下代码对我来说很好用:

@client.command() # As you use client.wait_for
async def destroy(ctx):
    def check(m):
        return m.author == ctx.author and m.channel == ctx.message.channel

    await ctx.message.delete()
    em = discord.Embed(color=15859772, title=":rotating_light: WARNING WARNING :rotating_light:",
                        description=f"{ctx.author.mention} Are you sure you want to run this command? yes/no")
    await ctx.send(embed=em)
    # for user input
    response = await client.wait_for('message', check=check)

    if response.content.lower() == 'yes':
        await ctx.send("Done")
    else:
        await ctx.send("Canceled")

如果您仍然有错误,我假设您以错误的方式使用 commands.command/定义错误。