discord.py message.author.id返回追溯

问题描述 投票:0回答:1

因此,我试图使我的discord.py机器人仅接受某些用户对某些命令的命令执行。 ctx.author.id表示机器人作者ID,我现在知道。我听说message.author.id应该可以工作,但是使用message.author.id会引发回溯,这是臭名昭著的NameError错误。为什么以及如何解决?

async def shutdown(ctx):
     if ctx.author.id == 436646726204653589 or 525334420467744768 or 218142353674731520:
        embed = discord.Embed(color = 0xff0000)
        embed.add_field(name="Shutdown Command Sent, Bot Rebooting in 3 seconds", value = str, inline = False)
        await ctx.send(embed=embed)
        await asyncio.sleep(3)
        await bot.close()
        os.execl(sys.executable, sys.executable, * sys.argv)
        os.system("py -3 theBot.py")

bot.run(TOKEN)```
python-3.x discord.py
1个回答
0
投票

如果使用the commands extension,并且shutdown是命令,则ctxContext对象。Context是命令消息的作者,并且是Context.author的简写。两者都是Context.author对象,您可以从中使用Message.author

© www.soinside.com 2019 - 2024. All rights reserved.