【发布时间】:2020-02-07 05:40:58
【问题描述】:
所以我试图让我的 discord.py 机器人只接受某些用户对某些命令的命令执行。我现在知道 ctx.author.id 表示机器人作者 ID。我听说message.author.id 应该可以工作,但使用message.author.id 会引发回溯,即臭名昭著的 NameError 错误。为什么以及如何解决?
@bot.command(description="Restarts The Bot's source file, use if bot freezes etc, [OWNER]")
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)
【问题讨论】:
-
message未在代码中的任何位置定义。其他人可能在它被定义后使用它,通常作为函数的参数。另请注意,您的if条件应为if ctx.author.id in (436646726204653589, 525334420467744768, 218142353674731520)
标签: python python-3.x discord.py