在discord.py 1.0.1 (只有Repl.it版本)中,齿轮给我带来了困难。
import discord
from discord.ext import commands
class Coding(commands, Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print("Kahoot Bot 0.1 ALPHA")
client.remove_command("help")
@commands.command()
async def clear(self, ctx, amount = 5):
await ctx.channel.purge(limit = amount + 1)
@commands.command()
async def ping(self, ctx):
await ctx.send(f"Pong! {round(client.latency * 1000)}ms.")
@client.command(pass_context = True, aliases = ["print"])
async def printing(ctx, *, what_to_print):
await ctx.send(what_to_print)
print(what_to_print)
def setup(client):
client.add_cog(Coding(client))错误的要点是: A)客户端没有定义B) init()应该返回None,而不是coroutine
我尝试过将我的所有代码更改为bot并返回到客户端,但是没有任何帮助。不知道怎么回事。
发布于 2020-03-17 11:07:47
你做错了遗产继承。您不能继承类:“命令”和"Cog“。您继承自类:"commands.Cog“。因此,将:class Coding(commands, Cog):更改为class Coding(commands.Cog):将修复一些错误。
您还做了以下错误(“客户端不存在”错误):
@commands.Cog.listener()
async def on_ready(self):
print("Kahoot Bot 0.1 ALPHA")
client.remove_command("help") # this line当我们想要访问一个类变量时,我们在这个变量的开头使用self.来表示我们正在使用这个类变量。在这种情况下,您不用self.client.,而是使用client.
由于在该函数中未定义客户端,因此会出现错误。但是它被定义为一个类变量( "init“函数)。要访问它,请使用:self.client.
https://stackoverflow.com/questions/60717971
复制相似问题