我正在尝试将存储在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'
答案 0 :(得分:0)
guild.get_member(author_id)
返回None
。
您必须首先检查收到的作者是否是成员对象。
进一步,您可能未启用会员意图。 Enable that或使用coroutine fetch_member