【问题标题】:mention a member with discord.py使用 discord.py 提及成员
【发布时间】:2021-11-25 05:39:36
【问题描述】:

你好,我想提一下我公会中的一个特定成员,我知道我的代码很乱,你能告诉我我的错误吗?

async def ping(ctx):
    guild=ctx.guild(889583100286369832)
    sido=guild.get_member('439800066312503297')
    await ctx.send(sido.mention)

【问题讨论】:

  • 当前行为是什么?
  • 我收到一个错误
  • 发布完整的错误信息。

标签: python python-3.x discord discord.py bots


【解决方案1】:

另一种方式:

sido = await bot.fetch_user(439800066312503297)
await ctx.send(sido.mention)

您需要这样做的意图: https://discordpy.readthedocs.io/en/stable/intents.html

【讨论】:

    【解决方案2】:

    您尚未发布错误消息。但 Discord 需要有特殊意图才能获取有关用户的公会数据。

    你不需要用户的公会数据来@他们,所以你不需要启用它。你可以这样做:

    myid = '<@[ID GOES HERE]>'
    await client.send_message(message.channel, ' : %s is the best ' % myid)
    

    【讨论】:

      【解决方案3】:

      没有看到错误,我不确定这是否是问题,但guild 可能没有get_member() 方法,您应该改用bot.get_member()

      如果这不是您的问题的原因,针对您的特定用例解决此问题的最佳方法是通过&lt;@ID&gt;提及用户

      await ctx.send("<@{}>".format("439800066312503297"))
      # Or
      await ctx.send("<@439800066312503297>")
      

      如果你想对 ID 进行硬编码,这里的格式化是不必要的,但如果你以后想动态更改 ID,我建议使用它。

      【讨论】:

        猜你喜欢
        • 2021-09-05
        • 1970-01-01
        • 2020-12-30
        • 1970-01-01
        • 2021-02-19
        • 2021-07-09
        • 1970-01-01
        • 2019-01-25
        • 2021-10-24
        相关资源
        最近更新 更多