![](/img/trans.png)
[英]How to fix “discord.ext.commands.errors.MissingRequiredArgument: author is a required argument that is missing.” in discord.py
[英]How to fix "discord.ext.commands.errors.MissingRequiredArgument: ctx is a required argument that is missing." in discord.py
我正在尝试做一个带有子类的简单机器人来处理命令,但我收到了这个错误
这是回溯:
忽略命令 teste 中的异常:Traceback(最近一次调用最后一次):文件“/home/mrtrue/.local/lib/python3.8/site-packages/discord/ext/commands/bot.py”,第 863 行,invoke await ctx.command.invoke(ctx) 文件“/home/mrtrue/.local/lib/python3.8/site-packages/discord/ext/commands/core.py”,第 721 行,在调用 await self.prepare( ctx) 文件“/home/mrtrue/.local/lib/python3.8/site-packages/discord/ext/commands/core.py”,第 685 行,准备等待 self._parse_arguments(ctx) 文件“/home/ mrtrue/.local/lib/python3.8/site-packages/discord/ext/commands/core.py”,第 599 行,在 _parse_arguments 转换 = await self.transform(ctx, param) 文件“/home/mrtrue/. local/lib/python3.8/site-packages/discord/ext/commands/core.py", line 445, in transform raise MissingRequiredArgument(param) discord.ext.commands.errors.MissingRequiredArgument: ctx 是一个必需的参数丢失的。
这里是代码:
import discord
from discord.ext import commands
import inspect
class BotLibertarin(commands.Bot):
client = discord.Client()
@client.event
async def on_message(self,message):
print(f"message from {message.author} what he said {message.content}")
await self.process_commands(message)
class CommandsHandler(BotLibertarin):
def __init__(self):
super().__init__(command_prefix=".")
members = inspect.getmembers(self)
for name, member in members:
if isinstance(member,commands.Command):
if member.parent is None:
self.add_command(member)
@commands.command()
async def teste(self,ctx):
await ctx.channel.send("teste")
我真的建议您花时间阅读文档。 我还要提醒您,在没有发出特定命令(例如!commandname)的情况下发送消息是违反 ToS 的[即使没有人明显遵循 ToS]。
无论哪种方式。 尝试这个:
import discord
from discord.ext import commands
client = commands.Bot(command.prefix='!')
@client.event
async def on_message(message):
print(f"message from {message.author} what he said {message.content}")
await message.channel.send(message.content)
@client.command()
async def teste(ctx):
await ctx.channel.send("teste")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.