【问题标题】:discord.py on_member_update game activitydiscord.py on_member_update 游戏活动
【发布时间】:2021-05-22 14:06:22
【问题描述】:

我正在尝试打印会员当前的活动(玩游戏) 但是当我打印 after.activity.name 时,它给了我我的自定义状态

@client.event
async def on_member_update(before, after):
    print(after.activity.name)

打印after.activity.type给我ActivityType.custom

当打印after.activties 时,它会打印:

(<CustomActivity name='808s & heartbreak' emoji=None>, <Activity type=<ActivityType.playing: 0> name='League of Legends' url=None details="Summoner's Rift (Normal)" application_id=401518684763586560 session_id=None emoji=None>)

【问题讨论】:

  • 您的代码有效,但Member.activity 不仅包括正在玩的游戏,还包括自定义活动、他正在听的音乐、流媒体等。只要有来自服务器的任何Member 的更改,不仅在活动中,这就是为什么您会看到自己的状态被触发。
  • 有没有办法只选择ActivityType.playing

标签: python-3.x discord.py


【解决方案1】:

过滤类型不是playing的活动

@client.event
async def on_member_update(before, after):
    game = [i for i in after.activities if str(i.type) == "playing"]
    if game:
        print(game[0].name)

【讨论】:

  • 感谢工作。但我不得不把它改成game = [i for i in after.activities if str(i.type) == "ActivityType.playing"]
猜你喜欢
  • 1970-01-01
  • 2021-05-17
  • 1970-01-01
  • 2021-06-10
  • 2021-10-06
  • 2021-07-25
  • 2021-02-26
  • 1970-01-01
  • 2018-08-14
相关资源
最近更新 更多