前提
dscord.py(py-cord)ですべてのロールを表示させようとしています。
実現したいこと
全ロールを表示させる
発生している問題・エラーメッセージ
Ignoring exception in command userinfo: Traceback (most recent call last): File "C:\Users\ren07\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\commands\core.py", line 124, in wrapped ret = await coro(arg) ^^^^^^^^^^^^^^^ File "C:\Users\ren07\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\commands\core.py", line 980, in _invoke await self.callback(ctx, **kwargs) File "D:\BOT\main.py", line 289, in userinfo embed.add_field(name="全ロール",value=member.all_roles.mention,inline=False) ^^^^^^^^^^^^^^^^ AttributeError: 'Member' object has no attribute 'all_roles' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "C:\Users\ren07\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\bot.py", line 1114, in invoke_application_command await ctx.command.invoke(ctx) File "C:\Users\ren07\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\commands\core.py", line 375, in invoke await injected(ctx) File "C:\Users\ren07\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\commands\core.py", line 132, in wrapped raise ApplicationCommandInvokeError(exc) from exc discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: AttributeError: 'Member' object has no attribute 'all_roles'
該当のソースコード
python
1@bot.slash_command(name=f"userinfo",description=f"ユーザーの詳細を取得します") 2async def userinfo(Interaction, member: discord.Option(discord.Member, description="詳細を取得するユーザーを選択してください!", required=False)): 3 botoruser=Interaction.author.bot 4 if not member: 5 member = Interaction.author 6 if botoruser==False: 7 botoruser="いいえ" 8 if botoruser==True: 9 botoruser="はい" 10 activit=member.activity 11 if activit=="None": 12 activit="無し" 13 embed=discord.Embed(title=f"userinfo - {member}", color=discord.Colour.purple()) 14 embed.set_author(name=member, icon_url=member.avatar.url) 15 embed.set_thumbnail(url=member.avatar.url) 16 embed.add_field(name="ユーザーネーム", value=member.name, inline=False) 17 embed.add_field(name="ユーザーdiscriminator",value="#"+member.discriminator,inline=False) 18 embed.add_field(name="ユーザーid", value=member.id, inline=False) 19 embed.add_field(name="ユーザーアクティビティ",value=activit,inline=False) 20 embed.add_field(name="最上位ロール",value=member.top_role,inline=False) 21 embed.add_field(name="全ロール",value=member.all_roles.mention,inline=False) 22 embed.add_field(name="人間:bot", value=botoruser, inline=False) 23 embed.add_field(name="アカウント作成時間", value=member.created_at.__format__("%Z : %Y/%m/%d %H:%M:%S"), inline=False) 24 embed.add_field(name="サーバー参加日時", value=member.joined_at.__format__("%Z : %Y/%m/%d %H:%M:%S"), inline=False) 25 await Interaction.send(embed=embed,delete_after=600)
現在のソースコード
python
1@bot.slash_command(name=f"userinfo",description=f"ユーザーの詳細を取得します") 2async def userinfo(Interaction, member: discord.Option(discord.Member, description="詳細を取得するユーザーを選択してください!", required=False)): 3 botoruser=Interaction.author.bot 4 if not member: 5 member = Interaction.author 6 if botoruser==False: 7 botoruser="いいえ" 8 if botoruser==True: 9 botoruser="はい" 10 activit=member.activity 11 if activit=="None": 12 activit="無し" 13 memberroles=len(member.roles) 14 embed=discord.Embed(title=f"userinfo - {member}", color=discord.Colour.purple()) 15 embed.set_author(name=member, icon_url=member.avatar.url) 16 embed.set_thumbnail(url=member.avatar.url) 17 embed.add_field(name="ユーザーネーム", value=member.name, inline=False) 18 embed.add_field(name="ユーザーdiscriminator",value="#"+member.discriminator,inline=False) 19 embed.add_field(name="ユーザーid", value=member.id, inline=False) 20 embed.add_field(name="ユーザーアクティビティ",value=activit,inline=False) 21 embed.add_field(name="最上位ロール",value=member.top_role.mention,inline=False) 22 embed.add_field(name="全ロール",value=get(member.roles),inline=False) 23 embed.add_field(name="ユーザーのロール数",value=memberroles-1,inline=False) 24 embed.add_field(name="人間:bot", value=botoruser, inline=False) 25 embed.add_field(name="アカウント作成時間", value=member.created_at.__format__("%Z : %Y/%m/%d %H:%M:%S"), inline=False) 26 embed.add_field(name="サーバー参加日時", value=member.joined_at.__format__("%Z : %Y/%m/%d %H:%M:%S"), inline=False) 27 await Interaction.send(embed=embed,delete_after=600)
試したこと
all_rolesをall_roleにする
補足情報
py-cord 2.3.2
aiohttp 3.8.3
get(member.roles)にしてみましたが、全ロールは表示できませんでした

回答2件
あなたの回答
tips
プレビュー