找不到命令 - Discord.py
Command not found - Discord.py
我正在尝试借助 Python 和 discord.py 库创建一个机器人。
我有两个文件main.py和MyBot.py。
Main.py
from MyBot import MyBot
bot = MyBot()
bot.run("API_KEY")
MyBot.py
from discord.ext import commands
from discord.ext.commands import command
class MyBot(commands.Bot):
def __init__(self):
super().__init__(command_prefix="!")
async def on_ready(self):
print("Bot ready.")
@command(name="hello", help="Say hello")
async def hello(ctx, arg):
await ctx.channel.send("Hello you!")
当 运行 命令 !hello
我的脚本出现异常
Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "hello" is not found
我认为错误来自于我使用装饰器的方式,但我不知道如何修复它。
请注意,我目前正在学习 python 协程和装饰器。所以这对我来说是一个新概念。
无论如何,非常感谢愿意帮助我的人:)
如果您想从 commands.Bot 继承,请使用:
from discord.ext import commands
from discord.ext.commands import command
class MyBot(commands.Bot):
def __init__(self):
super().__init__(command_prefix="!")
async def on_ready(self):
print("Bot ready.")
bot = MyBot()
@bot.command(name="hello", help="Say hello")
async def hello(ctx, arg):
await ctx.channel.send("Hello you!")
bot.run('token')
如果您继承自 MyBot 作为对命令进行分组的方法,请使用 cogs。在目前的状态下,继承自 commands.Bot 没有实际用途。
我正在尝试借助 Python 和 discord.py 库创建一个机器人。
我有两个文件main.py和MyBot.py。
Main.py
from MyBot import MyBot
bot = MyBot()
bot.run("API_KEY")
MyBot.py
from discord.ext import commands
from discord.ext.commands import command
class MyBot(commands.Bot):
def __init__(self):
super().__init__(command_prefix="!")
async def on_ready(self):
print("Bot ready.")
@command(name="hello", help="Say hello")
async def hello(ctx, arg):
await ctx.channel.send("Hello you!")
当 运行 命令 !hello
我的脚本出现异常
Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "hello" is not found
我认为错误来自于我使用装饰器的方式,但我不知道如何修复它。 请注意,我目前正在学习 python 协程和装饰器。所以这对我来说是一个新概念。
无论如何,非常感谢愿意帮助我的人:)
如果您想从 commands.Bot 继承,请使用:
from discord.ext import commands
from discord.ext.commands import command
class MyBot(commands.Bot):
def __init__(self):
super().__init__(command_prefix="!")
async def on_ready(self):
print("Bot ready.")
bot = MyBot()
@bot.command(name="hello", help="Say hello")
async def hello(ctx, arg):
await ctx.channel.send("Hello you!")
bot.run('token')
如果您继承自 MyBot 作为对命令进行分组的方法,请使用 cogs。在目前的状态下,继承自 commands.Bot 没有实际用途。