質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Discord

Discordは、ゲーマー向けのボイスチャットアプリです。チャット・通話がブラウザ上で利用可能で、個人専用サーバーも開設できます。通話中でも音楽を流したり、PC画面を共有できるなど多機能な点が特徴です。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

2回答

954閲覧

全ロールを取得したい

Rea

総合スコア8

Discord

Discordは、ゲーマー向けのボイスチャットアプリです。チャット・通話がブラウザ上で利用可能で、個人専用サーバーも開設できます。通話中でも音楽を流したり、PC画面を共有できるなど多機能な点が特徴です。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2022/12/17 03:27

編集2022/12/17 03:54

前提

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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Rea

2022/12/17 03:48

get(member.roles)にしてみましたが、全ロールは表示できませんでした
guest

回答2

0

自己解決

for role in guild.roles: if role.name!="@everyone": rolelist.append(role.mention) rolelist=','.join(rolelist)

これでできました

投稿2022/12/17 12:40

Rea

総合スコア8

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Act_Celery

2022/12/20 15:02

それだとguild全体のロールになりユーザーの持っているロールではなくなりますが大丈夫でしょうか?
Rea

2023/01/28 04:06

member.rolesにしました。
guest

0

'Member'オブジェクトには、'all_roles'というアトリビュートはありません、とおっしゃってます(そのまんま)
'Member'オブジェクトってなんでしょうか

投稿2022/12/17 03:34

y_waiwai

総合スコア87747

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Rea

2022/12/17 03:42

@bot.slash_command(name=f"userinfo",description=f"ユーザーの詳細を取得します") async def userinfo(Interaction, member: discord.Option(discord.Member, description="詳細を取得するユーザーを選択してください!", required=False)): のmemberです
Act_Celery

2022/12/20 15:02

discord.Memberです。 というかそれしかありえないと思います。 適当に答えるのやめたほうがいいと思います。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問