【问题标题】:Discordpy mention user from stringDiscordpy 从字符串中提及用户
【发布时间】:2021-10-16 09:54:52
【问题描述】:

如何从用户字符串列表中添加@提及?我想通知那些选定的用户。

sample_text: @user#tag

这将是纯文本,无法提及。尝试遍历成员并将其保存为对象,但只返回机器人。

示例代码:

async def on_message(self, message):
(...)
            embed = discord.Embed(title=c.LFG_OVER, description="Party:", color=c.COLOUR_BANANA)
            embed.set_author(name=f"{message.author.display_name}", url="", icon_url=f"{message.author.avatar_url}")
            embed.set_thumbnail(url=c.LFG_TY)

            embed.add_field(name="_", value=f"This is text: {list1[0]}\nThis is text: {list1[1]}\nThis is text: {list2[0]}\nThis is text: {list2[1]}", inline=True)
            embed.add_field(name="_", value=f"This is text: {list3[0]}\nThis is text: {dps[1]}\nThis is text: {list3[2]}\nThis is text: {list3[3]}", inline=True)

            await message.channel.send(embed=embed)

【问题讨论】:

  • 您需要他们的用户 ID。

标签: python discord.py


【解决方案1】:

使用discord.utils.get,您可以从他们的姓名和# 中获取成员对象,然后使用member.mention 提及他们:

#members is your list of members (format is name#1111)
for str_member in members:
    member = discord.utils.get(message.guild.members, name=str_member[:-5], discriminator=str_member[-4:]) 
    #using member.mention you can mention the person now, or save the mention in a list or whatever you want to do

【讨论】:

  • 执行message.guild.members 只会返回机器人本身。 [<Member id=0000000000 name='Name' discriminator='1068' bot=True nick=None guild=<Guild id=0000000000 name='Name' shard_id=None chunked=False member_count=30>>]
  • 您是否启用了成员意图,如this 回答中所述?
猜你喜欢
  • 2015-01-07
  • 1970-01-01
  • 2013-02-22
  • 2020-08-24
  • 2011-07-21
  • 2019-10-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多