Ad

Get Bot's Status Discord.py

- 1 answer

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. How can I "convert" my bot to a Member?

Ad

Answer

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:
Ad
source: stackoverflow.com
Ad