如何修复错误,但同时类和self应该保留?
这里是追溯:
Traceback(上次调用(:文件";C: \Users\sasha\AppData\Local\Programs\Python38\lib\site packages\discord\ext\commands\bot.py",第939行,调用中等待ctx.command.ioke(ctx(文件";C: \Users\sasha\AppData\Local\Programs\Python38\lib\site packages\discord\ext\commands\core.py",第855行,调用中等待自我准备(ctx(文件";C: \Users\sasha\AppData\Local\Programs\Python38\lib\site packages\discord\ext\commands\core.py",第789行,准备中等待自我_parse_arguments(ctx(文件";C: \Users\sasha\AppData\Local\Programs\Python38\lib\site packages\discord\ext\commands\core.py",第697行,在_parse_arguments中transformed=等待self.transform(ctx,param(文件";C: \Users\sasha\AppData\Local\Programs\Python38\lib\site packages\discord\ext\commands\core.py",第542行,在变换中引发MissingRequiredArgument(param(discord.ext.commands.errors.MissingRequiredArgument:ctx是一个缺少的必需参数。
下面是代码:
#!/usr/bin/python3
from discord.ext import commands
import discord
import inspect
class StarBot(commands.Bot):
def __init__(self, command_prefix, **options):
super().__init__(command_prefix, **options)
members = inspect.getmembers(self)
for name, member in members:
if isinstance(member, commands.Command):
if member.parent is None:
self.add_command(member)
async def on_ready(self):
print('Logged on as {0}!'.format(self.user))
@commands.command(name='reg', help='Для регистрации', pass_context=True)
async def reg(self, ctx):
if ' '.join(str(ctx.channel).split(' ')[:2]) == 'Direct Message':
await self.embed(ctx.channel, "Начало регистрации")
async def embed_channel(self, channel, title, string='', color=0xff9900):
embed = discord.Embed(color=color, title=title, description=string)
msg = await channel.send(embed=embed)
return msg
intents = discord.Intents.all()
bot = StarBot(command_prefix='/', intents=intents)
bot.run(TOKEN)
此处的代码问题:
@commands.command(name='reg', help='Для регистрации', pass_context=True)
async def reg(self, ctx):
if ' '.join(str(ctx.channel).split(' ')[:2]) == 'Direct Message':
await self.embed(ctx.channel, "Начало регистрации")
这里,你有(self,ctx(:
async def reg(self, ctx):
在一个齿轮中,它需要是(客户端,ctx(:
async def reg(client, ctx):
它应该看起来像:
@commands.command(name='reg', help='Для регистрации', pass_context=True)
async def reg(client, ctx):
if ' '.join(str(ctx.channel).split(' ')[:2]) == 'Direct Message':
await self.embed(ctx.channel, "Начало регистрации")