简体   繁体   English

机器人无法使用斜杠命令检测用户存在 discord.py

[英]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.我最近遇到了斜杠命令的问题,我检查了我的意图并且我都启用了,每当我使用我的 userinfo 命令的斜杠命令变体时,当用户的状态不是离线时,它会将用户的存在标记为“离线”。 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) (基本上总结一下,定期使用带有前缀的命令是有效的,但使用命令作为斜杠命令不会检测到正确的状态)

Discord have recently updated intents rules, check your app on the developer portal ( https://discord.com/developers/ ) in the bot section Discord 最近更新了意图规则,请在 bot 部分的开发人员门户( https://discord.com/developers/ )上检查您的应用

This is because Discord does not return the presence in the interaction callback, so you are getting partial information.这是因为 Discord 没有在交互回调中返回存在,所以你得到了部分信息。 Forks of dpy have fixed this by automatically checking the cache, but you can do so manually by writing code such as dpy 的分支已通过自动检查缓存来解决此问题,但您可以通过编写代码手动执行此操作,例如

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM