MemberConverter是否可以将服务器中的@recomment作为id读取


import discord
from discord import commands
@client.command()
async def check(current, content: str, member: commands.MemberConverter):
status = None
for member in current.guild.members:
if str(member.mention) == content:
status = member.status
break

当我在服务器中键入#check @mention时,它返回错误

discord.ext.commands.errors.MissingRequiredArgument: member is a required argument that is missing.

有人知道它为什么不见了吗?

当前代码需要两个参数:

  • 字符串类型的内容
  • 成员可以是任何类型的成员,例如

根据你的帖子,据我所知,你只想传递一个参数,即成员。因此,您的代码需要如下所示:

import discord
from discord import commands
@client.command()
async def check(current, searched_member: commands.MemberConverter):
status = None
for member in current.guild.members:
if member.id == searched_member.id:
status = member.status
break

更改:

  • 我删除了";内容";函数的参数,因为不需要
  • 我把";成员";参数名称由";searched_member";因为您已经使用了变量名称";成员";当迭代公会成员时
  • 我将比较更改为两个id之间的比较,因为成员转换器已经返回了一个成员对象。身份证是确保你谈论的是同一个会员的最简单方法

现在说到这一点,因为成员转换器已经返回了一个成员对象,所以整个循环通过公会成员的过程是完全不必要的。只需直接从成员对象获取状态:

import discord
from discord import commands
@client.command()
async def check(current, searched_member: commands.MemberConverter):
status = searched_member.status

您可以使用message.mentions[0],这将从消息中获取上述成员

最新更新