【问题标题】:Pinging in an embed doesn't work correctly with discord.py使用 discord.py 无法在嵌入中正常工作
【发布时间】:2020-05-06 18:42:33
【问题描述】:
@bot.event
async def on_member_join(ctx):
user1 = discord.Member
channel = bot.get_channel(654805249311375400)
embed= discord.Embed(title='Welcome to Kitty\'s Play Place <3', description='Welcome! We hope you enjoy your time at Kitty\'s play place {} \n ----------------------------------------------------------------------- \n Please check <#654820877304856606> to avoid any problems \n after please go to <#654806729162227743> and <#654806701123567616> \n To gain access to our chats, click the reaction in the channels mentioned above \n ----------------------------------------------------------------------- \n'. format(user1), colour=discord.Color.red())
embed.set_image(url='https://cdn.discordapp.com/attachments/654804320222707723/665897722213171205/ezgif-7-ec547b785e7d.gif')
await channel.send(embed=embed)

所以我有这段代码,奇怪的是它可以工作,除了用户 ping 显示为:

&lt;class 'discord.member.Member'&gt;

而不是username

谁能告诉我该怎么做?

【问题讨论】:

  • 你试过user.mention吗? discordpy.readthedocs.io/en/latest/…
  • 我会把它放在哪里?
  • 它现在给了我这个
  • 究竟你认为&lt;class 'discord.member.Member'&gt;会是什么,而不是现在的样子?

标签: python bots discord discord.py discord.py-rewrite


【解决方案1】:

忽略不正确的缩进,您将 Member 类本身分配给 user
您需要使用该类的实例。

请参阅How do I get a specific model? section of the FAQ in discord.py's documentation

如果您打算使用刚刚加入的成员,on_member_join 将通过 Member 对象,而不是 Context 对象,您可以直接使用它。

一旦你有了特定的对象,你就可以使用Member.mention 属性对应的字符串来提及它们。

【讨论】:

    猜你喜欢
    • 2020-12-31
    • 2021-08-29
    • 1970-01-01
    • 2020-09-25
    • 2021-05-23
    • 2021-02-26
    • 1970-01-01
    • 2016-01-22
    • 1970-01-01
    相关资源
    最近更新 更多