MissingRequiredArgument:上下文是缺少的必需参数

发布于 2025-01-13 19:13:28 字数 977 浏览 2 评论 0原文

我还是新人(因为我休息了一下,几乎忘记了一切)。我正在编写一个 AFK 机器人,结果发生了这种情况...

错误:MissingRequiredArgument:上下文是缺少的必需参数。

代码:

@client.command()
async def start(ctx,context,user: discord.Member):
    def check(m):
        return m.author == ctx.author and m.channel == ctx.channel
    name = context.author.display_name
    author = context.author
    guild = context.guild
    AFKrole = discord.utils.get(guild.roles, name="AFK")
    if not AFKrole:
        AFKrole = await guild.create_role(name="AFK")
    await context.author.edit(nick=f"[AFK]{name}")
    await author.add_roles(AFKrole)
    await ctx.send(f"AFK Mode Started For **{author}**.")
    gt = await client.wait_for('message', check=check, timeout=180)
    if gt.content.lower() == "afk stop":
        await context.author.edit(nick=f"{name}")
        await author.remove_roles(AFKrole)
        await ctx.send(f"AFK Mode Stopped For **{author}**.")
    else:
        pass

请帮忙。

Im Still New (Because I Took A Break And Forgot Almost Everything). I Was Coding An AFK Bot And This Happened...

Error: MissingRequiredArgument: context is a required argument that is missing.

Code:

@client.command()
async def start(ctx,context,user: discord.Member):
    def check(m):
        return m.author == ctx.author and m.channel == ctx.channel
    name = context.author.display_name
    author = context.author
    guild = context.guild
    AFKrole = discord.utils.get(guild.roles, name="AFK")
    if not AFKrole:
        AFKrole = await guild.create_role(name="AFK")
    await context.author.edit(nick=f"[AFK]{name}")
    await author.add_roles(AFKrole)
    await ctx.send(f"AFK Mode Started For **{author}**.")
    gt = await client.wait_for('message', check=check, timeout=180)
    if gt.content.lower() == "afk stop":
        await context.author.edit(nick=f"{name}")
        await author.remove_roles(AFKrole)
        await ctx.send(f"AFK Mode Stopped For **{author}**.")
    else:
        pass

please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与他有关 2025-01-20 19:13:28

删除 context 参数并用 ctx 替换代码中的任何 context 部分。 ctx 已经是上下文。

前任。

name = ctx.author.display_name
author = ctx.author
guild = ctx.guild

Remove context parameter and replace any context part in the code with just ctx. ctx is already context.

Ex.

name = ctx.author.display_name
author = ctx.author
guild = ctx.guild
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文