如何通过discord.py获取Discord用户自定义状态?
我看过discord.py 文档。我唯一能找到的是Member.status https://discordpy.readthedocs.io/en/latest/api.html?highlight=status#discord.Member.status返回状态为:在线/离线/空闲/dnd。
但不是新的自定义状态值。
我也不是在寻找定制的存在。
你所追求的是CustomActivity
.
正如文档中所解释的,用户可以有多个活动,但请尝试一下大小:
@bot.command()
async def mycustomstatus(ctx):
for s in ctx.author.activities:
if isinstance(s, discord.CustomActivity):
await ctx.send(s)
稍微相关的说明:请记住,机器人无法设置自定义活动 https://github.com/Rapptz/discord.py/issues/2400截至撰写本答案时;只阅读它们。
EDIT:
如果您无法获取成员的活动,请确保您已启用特权意图:
import discord
intents = discord.Intents().all()
bot = commands.Bot(command_prefix=..., intents=intents)
And from your bot's application page:
参考:
- Member.activities https://discordpy.readthedocs.io/en/latest/api.html?highlight=status#discord.Member.activities
- discord.CustomActivity https://discordpy.readthedocs.io/en/latest/api.html?highlight=status#discord.CustomActivity
-
isinstance() https://docs.python.org/3/library/functions.html#isinstance-Python内置
- 特权意图 https://discordpy.readthedocs.io/en/latest/intents.html?#privileged-intents
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)