如何解决“名称‘bot’未定义”错误?

2024-04-19 18:44:53 发布

您现在位置:Python中文网/ 问答频道 /正文

伙计们,我正在制作一个不和谐的机器人,但我有一个错误,上面写着“名称‘机器人’未定义”。有人能帮忙吗? 谢谢

import discord
from discord.ext import commands
from discord.ext.commands import has_permissions

client = commands.Bot(command_prefix = ';')


@client.event
async def on_ready():
   print("{0.user} logged in as".format(client))
   

@bot.command(pass_context=True)
@has_permissions(administrator=True)
async def help(ctx):
   await ctx.send('Help')

client.run('TOKEN')

Tags: fromimportclienttruepermissionsasyncdef机器人
1条回答
网友
1楼 · 发布于 2024-04-19 18:44:53

您需要使用ClientBot来实例您的bot。 在代码中,您正在将bot实例化为Client,但尝试使用@bot.command()创建命令

您需要使用@client.command()@commands.command()

相关问题 更多 >