NameError:未定义名称“机器人”

时间:2020-08-19 18:45:00

标签: discord discord.py

我目前正在开发一个不和谐的机器人,并遇到了一个问题,即未定义“机器人”一词。

我已经尝试用客户端替换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.')

1 个答案:

答案 0 :(得分:1)

您需要创建bot的实例才能使其正常运行:

import discord
from discord.ext import commands

bot = discord.ext.commands.Bot(command_prefix = "your_prefix");

bot.run("your_token")