最近几天,我一直在尝试将用 discord.py 编写的 discord bot 的结构调整为更面向 OOP 的结构(因为放置函数并不理想)。
但我发现这样多的问题,我可以曾经预计,事情是,我想我的所有命令封装到一个单一的类,但我不知道什么装饰使用和如何,我必须继承哪些类。
到目前为止,我已经实现了一个类似于下面的代码,它运行但在执行命令的那一刻它抛出这样的错误:discord.ext.commands.errors.CommandNotFound:找不到命令“状态”
PD:我使用的是 Python 3.6
from discord.ext import commands
class MyBot(commands.Bot):
def __init__(self, command_prefix, self_bot):
commands.Bot.__init__(self, command_prefix=command_prefix, self_bot=self_bot)
self.message1 = "[INFO]: Bot now online"
self.message2 = "Bot still online {}"
async def on_ready(self):
print(self.message1)
@commands.command(name="status", pass_context=True)
async def status(self, ctx):
print(ctx)
await ctx.channel.send(self.message2 + ctx.author)
bot = MyBot(command_prefix="!", self_bot=False)
bot.run("token")
Run Code Online (Sandbox Code Playgroud)