【问题标题】:NameError: name 'bot' is not definedNameError:名称'bot'未定义
【发布时间】:2020-08-20 23:20:14
【问题描述】:

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

我已经尝试用客户端替换 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.command 之后你还缺少() 它应该是这样的@bot.command()
  • 请生成minimal reproducible example。你在用discord.ext.commands.Bot吗?

标签: discord discord.py


【解决方案1】:

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

import discord
from discord.ext import commands

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

bot.run("your_token")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-24
    • 1970-01-01
    • 2021-04-15
    • 2019-01-26
    • 2021-10-05
    • 2017-08-16
    • 2019-08-18
    相关资源
    最近更新 更多