gpt4 book ai didi

python - 如何在discord.py(重写)中做出 channel 删除 react ?

转载 作者:行者123 更新时间:2023-12-04 09:37:32 25 4
gpt4 key购买 nike

所以,我做了一个命令 !vx new这会在某个类别中创建一个具有作者和管理员所有权限的新 channel 。现在我想创建一个删除票的命令 - !vx close .这是我想出的代码,它可以工作,但问题在于它可以从票证中的任何用户那里收到"is"。

@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 的用户用交叉/刻度标记作出 react ,如果作者对刻度作出 react ,它将关闭票证,如果作者对交叉作出 react ,则不会关闭。
编辑 - 上面的代码也不起作用。

最佳答案

您可以从函数的上下文 (ctx) 中获取 Member 对象以及来自 client.wait_for() 的消息。 .所以你可以有检查功能:

return m.content.lower() == 'yes' and ctx.message.author == m.author
对于表情符号位,您可以在 on_reaction_add 中放置一个 if 语句。事件说“如果我(机器人)发送的消息和消息内容是关闭的并且 react 表情符号同意并且用户具有'管理员'权限”
应要求的表情符号代码:
它看起来像这样。
    @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()

关于python - 如何在discord.py(重写)中做出 channel 删除 react ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62497785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com