【问题标题】:discord.py certain people execute commanddiscord.py 某些人执行命令
【发布时间】:2020-11-28 08:41:32
【问题描述】:

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


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")

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

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    您是否启用了intents.members?如果没有:

    intents = discord.Intents.default()
    intents.members = True
    
    bot = commands.Bot(..., intents=intents)
    

    还要确保在developer portal 中启用它们

    Reference

    【讨论】:

    • 我有 intents=discord.intents.all() 并启用了意图,但似乎没有修复它
    【解决方案2】:

    如果用户 ID 在列表中,您可以使用 check。如果作者不在,那么它会跳过他,你可以使用 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')
    

    【讨论】:

    • 谢谢你,但它似乎引发了检查失败
    猜你喜欢
    • 1970-01-01
    • 2020-12-31
    • 1970-01-01
    • 1970-01-01
    • 2020-08-22
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多