Phoenix
Phoenix

Reputation: 45

Bot unable to detect user presence with slash commands discord.py

I recently came across an issue with slash commands and I checked my intents and I have all enabled and whenever I use the slash command variant of my userinfo command, It marks the user's presence as "offline" when their status isn't offline. The prefixed command works however.

@client.hybrid_command(name = "userinfo", with_app_command=True, description="Get information about a user")
@app_commands.guilds(discord.Object(id = 1009907559391567912))
async def userinfo(ctx : commands.Context,member: discord.Member = None):
  datetime_format = "%a, %d %b %Y"
  if member == None:
    member = ctx.author
  mstatus = str(member.status)
  l = [
  ["dnd", "🔴 Do Not Disturb"],
  ["idle", "🟠 Idle"],
  ["online", "🟢 Online"],
  ["offline", "âš« Offline"]]
  for status in l:
    mstatus = mstatus.replace(status[0], status[1])
    roles = [role for role in member.roles[1:]]
    embed = discord.Embed(
    color = discord.Color(embedcolor),
    title = f"{member}")
    embed.add_field(name="**•Status•**", value=str(mstatus), inline=True)
    embed.set_thumbnail(url=f"{member.avatar.url}")
    embed.add_field(name=f"**•Roles• ({len(member.roles) - 1})**", value='• '.join([role.mention for role in roles]), inline=False)
    embed.add_field(name="**•Account Created At•**", value=f"{member.created_at.strftime(datetime_format)}", inline=True)
    embed.add_field(name="**•Joined Server At•**", value=f"{member.joined_at.strftime(datetime_format)}", inline = True)
    await ctx.reply(embed=embed)

Intents are also enabled for everything so what is the issue? (Basically to sum up, using the command regularly with the prefix works but using the command as a slash command doesn't detect the correct status)

Upvotes: 0

Views: 316

Answers (1)

DenverCoder1
DenverCoder1

Reputation: 2501

This is because Discord does not return the presence in the interaction callback, so you are getting partial information. Forks of dpy have fixed this by automatically checking the cache, but you can do so manually by writing code such as

member = interaction.guild.get_member(member.id)

Upvotes: 1

Related Questions