所以我刚开始对Discord-Bots进行编程,并想使用齿轮来保持一切井井有条。 现在我想在齿轮内部使用“客户端”:
齿轮文件:
import discord from discord.ext import commands class Manage(commands.Cog): def __init__(self, client): self.client = client ### Events ### @commands.Cog.listener() async def on_ready(self): print(f'We have logged in! xD') ### Commands ### @commands.command() async def ping(self, ctx): await ctx.send(f"Pong! Response time:{round(client.latency * 1000)}ms") def setup(client): client.add_cog(Manage(client))
我已将主文件连接到齿轮,并且一切正常,直到可以在齿轮文件中使用“客户端”为止。 请帮助<3
答案 0 :(得分:0)
您的课程开始应该看起来像
def __init__(self, bot):
self.bot = bot
在其余代码中。您可以在齿轮中使用self.bot
来引用客户