【发布时间】:2021-12-04 12:38:13
【问题描述】:
我的 ping 命令在 cog 中不起作用,但在我的 main.py 文件中起作用。这是齿轮的代码:
import discord
from discord.ext import commands
class Misc(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_ready(self):
print('Misc cog loaded\n-----')
@commands.command()
async def ping(self, ctx):
await ctx.send(f'pong!\n{round(bot.latency * 1000)}ms')
def setup(bot):
bot.add_cog(Misc(bot))
当我运行 ping 命令时出现此错误:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'bot' is not defined
【问题讨论】:
标签: python discord.py discord.py-rewrite