首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >吨焦耳误差

吨焦耳误差
EN

Stack Overflow用户
提问于 2020-03-17 07:30:01
回答 1查看 114关注 0票数 0

在discord.py 1.0.1 (只有Repl.it版本)中,齿轮给我带来了困难。

代码语言:javascript
复制
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并返回到客户端,但是没有任何帮助。不知道怎么回事。

EN

回答 1

Stack Overflow用户

发布于 2020-03-17 11:07:47

你做错了遗产继承。您不能继承类:“命令”和"Cog“。您继承自类:"commands.Cog“。因此,将:class Coding(commands, Cog):更改为class Coding(commands.Cog):将修复一些错误。

您还做了以下错误(“客户端不存在”错误):

代码语言:javascript
复制
    @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.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60717971

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档