discord.py - 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")
解决方案
我设法找到了问题并修复了它。
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
,它将设置在消息的作者上。
推荐阅读
- regex - 拆分分隔符分隔的字符串并插入到oracle 11中的表中
- c# - 如何使用 AES256 将 C# 加密/解密到 PHP/Soap 客户端/服务器通信
- google-diff-match-patch - diff_match_patch 可以为 diff2html 创建统一的差异字符串吗?
- caching - Redis 复制和 LFU 缓存
- c++ - 原子读取是否保证读取最新值?
- redhat - Icinga2 客户端 RHEL7 powerppc
- python - GAN 训练后输出噪声
- spring-boot - 如果属性不在 Spring Boot 应用程序文件中,Sprint boot 2.0.5 @ConfigurationProperties 不会填充列表
- python - 如何在一个 QTableWidget 中显示 2 个具有一对多关系的 SQLite 表
- arrays - 将数组的结果写入下一个可用单元格