如何在discord.py(重写)中做出频道删除反应?

2024-05-16 22:38:49 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,我做了一个命令!vx new,它创建了一个新的频道,在某个类别中设置了作者和管理员的所有权限。现在我想创建一个命令来删除票据-!vx close。这是我发现的代码,它可以工作,但问题是它可以从票据中的任何用户处接收“是”

@client.command(name='close', aliases=['delete'])
@commands.has_permissions(administrator=True)
async def close(ctx):
    await ctx.send("Do you want to delete this channel?")

    @commands.Cog.listener()
    async def on_reaction_add(self, reaction, user: discord.Member):

        def check(reaction, user):
            name_list = []
            for emoji in reaction.message.reactions:
                name_list.append(emoji.emoji)

            return '✅' in name_list and reaction.message.author.id == MyBotID and reaction.message.content == "Do you want to delete this channel?" and user.guild_permissions.administrator

        if check(reaction, user):
            await ctx.send("K!")
            await ctx.channel.delete()

我希望键入!vx close的用户使用叉号/勾号标记进行反应,如果作者使用勾号进行反应,该标记将关闭票据,如果作者使用叉号进行反应,则不会关闭票据

编辑-上述代码也不起作用


Tags: namemessageclosedefchannel作者awaitdelete
1条回答
网友
1楼 · 发布于 2024-05-16 22:38:49

您可以从函数的上下文(ctx)获取成员对象,从client.wait_for()获取消息。因此,您可以将检查功能设置为:

return m.content.lower() == 'yes' and ctx.message.author == m.author

对于emoji位,您可以在on_reaction_add事件中放置一条if语句,这样说“如果消息由我(bot)发送,消息内容用于关闭,并且emoji表示同意,并且用户具有“管理员”权限”

所需的表情符号代码: 它看起来像这样

    @commands.Cog.listener()
    async def on_reaction_add(self, reaction, user : discord.Member):

        def check(reaction, user):
            name_list = []
            for emoji in reaction.message.reactions:
                name_list.append(emoji.emoji)

            return '✅' in name_list and reaction.message.author.id == yourBotsID and reaction.message.content == "Do you want to delete this channel?" and user.guild_permissions.administrator

        if check(reaction, user):
            await ctx.send("K!")
            await ctx.channel.delete()

相关问题 更多 >