我正在尝试对我的机器人使用 ping 命令,它的代码在 cog 中。我知道出了什么问题,但我不知道如何解决它,因为我是新手。每当我使用“f.ping”命令时,我都会收到以下错误:
Ignoring exception in command ping:
Traceback (most recent call last):
File "C:\Users\josep\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\josep\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 847, in invoke
await self.prepare(ctx)
File "C:\Users\josep\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 784, in prepare
await self._parse_arguments(ctx)
File "C:\Users\josep\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 690, in _parse_arguments
transformed = await self.transform(ctx, param)
File "C:\Users\josep\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 535, in transform
raise MissingRequiredArgument(param)
discord.ext.commands.errors.MissingRequiredArgument: client is a required argument that is missing.
这是我的 ping.py 代码:
import discord
from discord.ext import commands
class Ping(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command()
async def ping(self, ctx):
await ctx.send(f'Pong!' ({round(client.latency * 1000)}ms))
def setup(client):
client.add_cog(Ping(client))
我已将问题/错误缩小到部分({round(client.latency * 1000)}ms,但我不知道如何解决它。该命令在删除该部分后工作得很好。任何帮助表示赞赏。
ibeautiful
慕哥6287543
相关分类