Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

python - How can I solve the "name 'bot' is not defined" error?

Guys I'm making a discord bot but i have an error it says "name 'bot' is not defined". Can anyone help? Thanks

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')
question from:https://stackoverflow.com/questions/65858549/how-can-i-solve-the-name-bot-is-not-defined-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to either use Client or Bot to instance your bot. In your code you are instancing the bot as Client, but you are trying to create a command using @bot.command().

You need to use either @client.command() or @commands.command().


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...