![](/img/trans.png)
[英]discord.py MemberNotFound exception when passing a real member
[英]Discord py MemberNotFound exception
@commands.command()
async def mute(self, ctx, member : discord.Member = None):
try:
if isinstance(member, discord.Member):
await member.edit(mute=True)
elif member is None: #setting the command to mute selected member
member=get(ctx.guild.members, id=Charles_id)
await member.edit(mute=True)
except discord.HTTPException:
await ctx.channel.send(f"User {member.mention} isn't connected to voice channel")
except discord.ext.commands.errors.MemberNotFound("@everyone"):
vc = ctx.author.voice.channel
for user in vc.members:
await user.edit(mute=True)
因此,我正在尝试发出使上述播放器静音的命令。 默认情况下,它应该使我们的朋友查尔斯静音。 唯一的问题是默认角色(@Everyone)。 我挣扎了很多,但最终我想出了一个可行的想法。 可悲的是它并没有真正起作用。 该计划是尝试获取成员,如果成员是@everyone,它将运行一个错误,该错误将触发除了并最终会做它的事情。 我对编程很陌生,所以我希望能得到有用的教训,干杯!
追溯如下:
Ignoring exception in command ryj:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 851, in invoke
await self.prepare(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 786, in prepare
await self._parse_arguments(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 697, in _parse_arguments
transformed = await self.transform(ctx, param)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 552, in transform
return await self.do_conversion(ctx, converter, argument, param)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 505, in do_conversion
return await self._actual_conversion(ctx, converter, argument, param)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 451, in _actual_conversion
ret = await instance.convert(ctx, argument)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/converter.py", line 191, in convert
raise MemberNotFound(argument)
discord.ext.commands.errors.MemberNotFound: Member "@everyone" not found.
我认为错误不言自明。 @everyone
不是会员,所以你不能转换它。
另一种选择是手动转换它:
async def mute(self, ctx, *, member_string: str):
if member_string == "@everyone":
return await ctx.send("You can't mention everyone")
# Converting the string to a `discord.Member` obj
member = commands.MemberConverter.convert(ctx, member_string)
if member.voice is None:
return await ctx.send("Member isn't in a voicec channel") # Exiting if the user isn't connected to any vs channel
await member.edit(mute=True)
参考:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.