如何解决NameError:未定义名称“机器人”
我目前正在开发一个不和谐的机器人,并遇到了一个问题,即未定义“机器人”一词。
我已经尝试用客户端替换bot,但是这会产生更多问题。 这是我的代码:
@bot.command()
async def kick(ctx,user: discord.Member,*,reason=None):
if user.guild_permissions.manage_messages:
await ctx.send('I cant kick this user because they are an admin/mod.')
elif ctx.author.guild_permissions.kick_members:
if reason is None:
await ctx.guild.kick(user=user,reason='None')
await ctx.send(f'{user} has been kicked by {ctx.message.author.mention}')
else:
await ctx.guild.kick(user=user,reason=reason)
await ctx.send(f'{user} has been kicked by {ctx.message.author.mention}')
else:
await ctx.send('You do not have permissions to use this command.')
解决方法
您需要创建bot
的实例才能使其正常运行:
import discord
from discord.ext import commands
bot = discord.ext.commands.Bot(command_prefix = "your_prefix");
bot.run("your_token")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。