简体   繁体   English

获取机器人的状态 discord.py

[英]Get bot's status discord.py

I'd like to get the bot's status whenever it is changed to make an action (for now it's just print when it comes online.).我想在更改机器人以执行操作时获取机器人的状态(现在它只是在联机时打印。)。

Unfortunately my approach doesn't work:不幸的是,我的方法不起作用:

@bot.event
async def on_member_update(usr_before, usr_after):
    if bot.user.status == discord.Status.online:
        print("becomes online!")

I think the problem is that the status isn't a User attribute but a Member attribute.我认为问题在于状态不是User属性而是Member属性。 How can I "convert" my bot to a Member ?如何将我的机器人“转换”为Member

I have it like this.我有这样的。

@client.event
async def on_ready():
print("Bot Online!")
print("Name: {}".format(client.user.name))
print("ID: {}".format(client.user.id))
await client.change_presence(game=discord.Game(name="d!help for help"))

try this:尝试这个:

member = None
for server in bot.servers:
    member = server.get_member(bot.user.id)
    break

if member.status == discord.Status.online:

or this:或这个:

if [s for s in bot.servers][0].get_member(bot.user.id).status == discord.Status.online:

Okay so actually, there's a discord.Server attribute (discord.Server.me) which does this x)好吧,实际上,有一个 discord.Server 属性 (discord.Server.me) 执行此操作 x)

https://discordpy.readthedocs.io/en/latest/api.html#discord.Server.me https://discordpy.readthedocs.io/en/latest/api.html#discord.Server.me

Haven't tested it though虽然没有测试过

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM