Yolixer
Yolixer

Reputation: 25

How would I detect user activities? | discord.py

I'm trying to make a bot that when a command is entered it detects a users activities. I wrote some code, but the response from the bot I get is not what I wanted. That's my code:

from discord import Member
from discord.ext import commands

bot = commands.Bot(command_prefix='!')


@bot.command()
async def status(ctx):
    await ctx.send(Member.activities)

bot.run('token')

And this is what I get in response:

<member 'activities' of 'Member' objects>

How can I fix this? Would anyone help me?

Upvotes: 1

Views: 5859

Answers (1)

Gugu72
Gugu72

Reputation: 2218

It seems you are new to python. Python is an object oriented programming language, means that you need to make the difference between a class and an instance.

In your case, you are fetching the class attribute, though you want the instance attribute.

What you wanted to do:

@bot.command
async def status(ctx):
  await ctx.send(ctx.author.activities)

Though, that would send a python-formatted list, so that's still not what you want.

What I guess you want to do:

@bot.command
async def status(ctx):
  await ctx.send(ctx.author.activities[0].name)

Please note, you need more code as this command like that would raise an error if the member doesn't have any activity.

Upvotes: 2

Related Questions