【问题标题】:Trying to get a member's status试图获取成员的状态
【发布时间】:2022-01-24 19:57:27
【问题描述】:

现在我正在 on_ready 做它只是为了尝试弄清楚..当我在线时状态返回“离线”..最终我希望在一个循环任务中执行此操作,我检查它们是否是 afk每隔一段时间。

https://imgur.com/a/EA3deJT 是我在 Discord 开发门户中的设置

无论如何,有什么想法是我搞砸的吗?

import discord
from discord.ext import commands
from discord.utils import get
import json

with open('variables.json') as f:
  variables = json.load(f)

intents = discord.Intents.all()
client = commands.Bot(command_prefix = ["!", "+", "-"], case_insensitive=True, intents= intents)

@client.event
async def on_ready():
    guild = await client.fetch_guild(796815848219476019)
    user = await guild.fetch_member(118900492607684614)
    print(user.status)

client.run(variables["TOKEN"])

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    所以使用get_guild 然后get_member 做到了,但还是很奇怪fetch 没有成功:/

    另一个奇怪的问题是我在使用fetch_guild 时不能使用get_member,但我可以反其道而行之。反正我明白了。对于任何可能偶然发现同样问题的人,这里是生成的代码。

    import discord
    from discord.ext import commands
    from discord.utils import get
    import json
    
    with open('variables.json') as f:
      variables = json.load(f)
    
    intents = discord.Intents.all()
    client = commands.Bot(command_prefix = ["!", "+", "-"], case_insensitive=True, intents= intents)
    
    @client.event
    async def on_ready():
        # guild = await client.fetch_guild(796815848219476019)
        # user = await guild.fetch_member(118900492607684614)
        guild = client.get_guild(796815848219476019)
        print(guild)
        user = guild.get_member(118900492607684614)
        print(user.status)
    
    client.run(variables["TOKEN"])```
    

    【讨论】:

      猜你喜欢
      • 2019-08-27
      • 2022-08-13
      • 2019-04-23
      • 1970-01-01
      • 2021-07-09
      • 2011-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多