使用 discord.py 提及成员
mention a member with discord.py
你好,我想提到我公会中的一个特定成员,我知道我的代码很乱,你能告诉我我的错误吗?
async def ping(ctx):
guild=ctx.guild(889583100286369832)
sido=guild.get_member('439800066312503297')
await ctx.send(sido.mention)
您还没有发布错误信息。但 discord 需要特殊意图才能获取有关用户的公会数据。
然而,您不需要用户的公会数据来@他们,所以您不需要启用它。你可以这样做:
myid = '<@[ID GOES HERE]>'
await client.send_message(message.channel, ' : %s is the best ' % myid)
另一种方式:
sido = await bot.fetch_user(439800066312503297)
await ctx.send(sido.mention)
你需要这样的意图:
https://discordpy.readthedocs.io/en/stable/intents.html
没有看到错误,我不确定这是否是问题所在,但 guild
可能没有 get_member()
方法,您应该改用 bot.get_member()
如果此 不是 问题的原因,针对您的特定用例解决此问题的最佳方法是使用 <@ID>
await ctx.send("<@{}>".format("439800066312503297"))
# Or
await ctx.send("<@439800066312503297>")
如果您想硬编码ID,则无需在此处格式化,但如果您以后想动态更改ID,我建议您使用它。
你好,我想提到我公会中的一个特定成员,我知道我的代码很乱,你能告诉我我的错误吗?
async def ping(ctx):
guild=ctx.guild(889583100286369832)
sido=guild.get_member('439800066312503297')
await ctx.send(sido.mention)
您还没有发布错误信息。但 discord 需要特殊意图才能获取有关用户的公会数据。
然而,您不需要用户的公会数据来@他们,所以您不需要启用它。你可以这样做:
myid = '<@[ID GOES HERE]>'
await client.send_message(message.channel, ' : %s is the best ' % myid)
另一种方式:
sido = await bot.fetch_user(439800066312503297)
await ctx.send(sido.mention)
你需要这样的意图: https://discordpy.readthedocs.io/en/stable/intents.html
没有看到错误,我不确定这是否是问题所在,但 guild
可能没有 get_member()
方法,您应该改用 bot.get_member()
如果此 不是 问题的原因,针对您的特定用例解决此问题的最佳方法是使用 <@ID>
await ctx.send("<@{}>".format("439800066312503297"))
# Or
await ctx.send("<@439800066312503297>")
如果您想硬编码ID,则无需在此处格式化,但如果您以后想动态更改ID,我建议您使用它。