【问题标题】:How can I solve the "name 'bot' is not defined" error?如何解决“未定义名称'bot'”错误?
【发布时间】:2021-04-27 17:03:28
【问题描述】:

伙计们,我正在制作一个不和谐的机器人,但我有一个错误,它说“名称'bot'未定义”。任何人都可以帮忙吗? 谢谢

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

【问题讨论】:

    标签: python error-handling discord bots


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-14
      • 1970-01-01
      • 2022-06-18
      • 1970-01-01
      • 2020-10-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多