因此,我试图使我的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)```
如果使用the commands extension,并且shutdown
是命令,则ctx
是Context
对象。Context
是命令消息的作者,并且是Context.author
的简写。两者都是Context.author
对象,您可以从中使用Message.author
。