繁体   English   中英

discord.py 某些人执行命令

[英]discord.py certain people execute command

所以我试图发出一个只有我和另一个人可以关闭机器人的注销命令,


trusted = {id, id}
    @commands.command()
    async def test(self, ctx):
        if ctx.author.id  in trusted:       
            await ctx.send(f"{ctx.author.mention} Closing Bot")
            await self.bot.close()
        else:
            await ctx.send("Only (me) and (my friend) can execute this")

出于某种原因,每当我尝试这样做时,它都没有意识到我是受信任的并且不会执行。

您是否启用了intents.members 如果不:

intents = discord.Intents.default()
intents.members = True

bot = commands.Bot(..., intents=intents)

还要确保在开发人员门户中启用它们

参考

您可以检查用户 ID 是否在列表中。 如果作者不在那里,那么它只会跳过他,您可以使用 error_handler 来发送错误。

def me_and_friends(ctx):
    trusted = [id, id]
    return ctx.author.id in trusted
@commands.command()
@commands.check(me_and_friends)
async def test(self, ctx):
    await ctx.send('This is either me or a friend')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM