首页 > 解决方案 > member.edit 中的“未定义错误‘Self’”

问题描述

我的代码有问题

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: edit() missing 1 required positional argument: 'self'

当我运行命令时。自我不应该被定义,对吧?另外,当我添加 self 时,我遇到了 ctx.xml 的问题。

编码:

import discord
from discord.ext import commands


client = commands.Bot(command_prefix="/")


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


@client.command(pass_context=True)
async def leave(ctx):
    await ctx.voice_client.disconnect()


client.run("Token")

标签: discord.pydiscord.py-rewrite

解决方案


我设法找到了问题并修复了它。

import discord
from discord.ext import commands


client = commands.Bot(command_prefix="/")


@client.command()
async def join(ctx):
    channel = ctx.author.voice.channel
    await channel.connect()
    await ctx.author.edit(mute=True)

@client.command()
async def leave(ctx):
    await ctx.voice_client.disconnect()


client.run("Token")

问题是,您包含member在您的功能中。如果您希望它发送、编辑或对消息作者执行某些操作,只需执行此操作ctx.author,它将设置在消息的作者上。


推荐阅读