如何使用 Discord.py 将用户 ID 转换为成员对象
How can i convert an user ID to a member object using Discord.py
我正在尝试将存储在 sqlite3 数据库中的用户 ID 转换为成员对象,以便我可以获得该用户的 .display_name
属性。
channel_id = ctx.channel.id
c.execute(f"SELECT * FROM deleted_messages WHERE channel_id={channel_id}")
array = c.fetchone()
message_text = array[1]
author_id = array[2]
guild = bot.get_guild(GUILD_ID) #Here I usually have the ID of the guild that the bot is in.
author = guild.get_member(author_id)
author.display_name #When I try to get the diplay_name of that member, I get the error.
这是我得到的错误:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'display_name'
guild.get_member(author_id)
这将返回 None
。
你要先确认你收到的作者是不是成员对象
此外,您可能没有启用会员意向。 Enable that or use the coroutine fetch_member
我正在尝试将存储在 sqlite3 数据库中的用户 ID 转换为成员对象,以便我可以获得该用户的 .display_name
属性。
channel_id = ctx.channel.id
c.execute(f"SELECT * FROM deleted_messages WHERE channel_id={channel_id}")
array = c.fetchone()
message_text = array[1]
author_id = array[2]
guild = bot.get_guild(GUILD_ID) #Here I usually have the ID of the guild that the bot is in.
author = guild.get_member(author_id)
author.display_name #When I try to get the diplay_name of that member, I get the error.
这是我得到的错误:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'display_name'
guild.get_member(author_id)
这将返回 None
。
你要先确认你收到的作者是不是成员对象
此外,您可能没有启用会员意向。 Enable that or use the coroutine fetch_member