1 回答
TA贡献1906条经验 获得超10个赞
使用message.mentions
message.mentions
discord.Member
返回提到的列表(或者discord.User
如果消息是在私人消息中发送的)。
# Safe method
if message.mentions:
member = message.mentions[0]
else:
return # There was no mentions
# Riskier but simpler method
# Having no mentions or more than one would raise an error
member, = message.mentions
快速说明:回复被视为提及,message.mentions将包含您的消息中提到的成员和您回复的成员。
解析消息
提及等同于<@!id>,因此您可以解析您的消息以获取成员的 id:
command, member = message.split()
member_id = int(member.strip('<@!>'))
然后,要从discord.Member中取出对象:
# Regardless of cache, but sends an API call
member = await bot.fetch_member(member_id)
# Depends on the bot's cache
# Doesn't make any API calls and isn't asynchronous
member = message.guild.get_member(member_id)
添加回答
举报