Ad
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. 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
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad