Home > Mobile >  Trying to get a member's status
Trying to get a member's status

Time:12-24

Right now I am doing it on_ready just to try and figure it out.. the status is returning "offline" when i am online.. Ultimately I am looking to do this within a looped task where i check whether they are afk every so often.

https://imgur.com/a/EA3deJT is my settings in the discord dev portal

Anyway, any ideas where i messed up?

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"])

CodePudding user response:

So using get_guild and then get_member did it, but still weird how fetch didn't work out :/

Another odd issue is that I can't use get_member when using fetch_guild, but i can do the inverse of that. Anyway I got it. For anyone that may stumble across this same issue, here is the resulting code.

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"])```

CodePudding user response:

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"])```
  • Related