【问题标题】:discord.ext.commands.errors.CommandInvokeError Command raised an exception: NameError: name 'self' is not defineddiscord.ext.commands.errors.CommandInvokeError 命令引发异常:NameError: name 'self' is not defined
【发布时间】:2020-09-21 01:27:49
【问题描述】:

我正在制作一个机器人,可以在人们加入 vc 时将其静音。但是,当我运行以下代码时,我收到关于未定义“自我”的错误。我该如何解决这个问题?

async def join(ctx, *, member=discord.Member):
    channel = ctx.author.voice.channel
    await channel.connect()
    await member.edit(mute=True)

【问题讨论】:

  • 你是在齿轮里面做这个吗?如果是的话,就试着把第一个参数self.

标签: discord.py discord.py-rewrite


【解决方案1】:

如果您在 Class/Cog 中,则需要将 self 作为第一个参数传递。

async def join(self, ctx, *, member=discord.Member):
    channel = ctx.author.voice.channel
    await channel.connect()
    await member.edit(mute=True)

【讨论】:

    猜你喜欢
    • 2021-03-23
    • 1970-01-01
    • 2022-01-02
    • 2015-01-20
    • 1970-01-01
    • 1970-01-01
    • 2022-12-02
    • 2018-12-12
    • 2017-11-15
    相关资源
    最近更新 更多