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

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

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

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

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

解決済

1回答

3963閲覧

discord py 2.0 の button でインタラクションエラーが発生する。

lawliet

総合スコア10

Discord

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

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2022/06/19 10:51

discord py 2.0 でボタン処理を実装しようとしています。

Pythonバージョン:Python 3.10.4
使用モジュール:discord.py @ git+https://github.com/Rapptz/discord.py@9648986028a9721e1ba733750eb8c30e163dcb2c

こちらのチュートリアルを参考に以下のコードを記載しました。
https://gist.github.com/lykn/bac99b06d45ff8eed34c2220d86b6bf4

Python

1# Note: This is just an "improved" code of what's shown above and that's how it's going to work throughout the gist the above code is going to be refined over and over again. 2import discord 3from discord.ext import commands 4 5intents = discord.Intents.all() 6client = commands.Bot(command_prefix=".", intents=intents) 7 8 9class Buttons(discord.ui.View): 10 def __init__(self, *, timeout=180): 11 super().__init__(timeout=timeout) 12 13 @discord.ui.button(label="Button", style=discord.ButtonStyle.gray) 14 async def blurple_button(self, button: discord.ui.Button, interaction: discord.Interaction): 15 button.style = discord.ButtonStyle.green 16 await interaction.response.edit_message(content=f"This is an edited button response!", view=self) 17 18 19@client.command() 20async def button(ctx): 21 await ctx.send("This message has buttons!", view=Buttons()) 22 23token = "TOKEN" 24client.run(token) 25

.button コマンドを使用すると、ボタン が表示されますが、押してもインタラクションエラーとなっていまいます。

エラーは以下のとおりです。

Error

1Ignoring exception in view <Buttons timeout=180 children=1> for item <Button style=<ButtonStyle.secondary: 2> url=None disabled=False label='Button' emoji=None row=None>: 2Traceback (most recent call last): 3 File "C:\Users\KOMATSU\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ui\view.py", line 414, in _scheduled_task 4 await item.callback(interaction) 5 File "c:\Users\KOMATSU\practice\test.py", line 15, in blurple_button 6 button.style = discord.ButtonStyle.green 7AttributeError: 'Interaction' object has no attribute 'style'

await interaction.response.edit_message(content=f"This is an edited button response!", view=self)
を、await interaction.response.send_message("ボタンがクリックされました", ephemeral=True) に変更しても同様のErrorがでます。

やりたいこと
正常にインタラクションに対してレスポンスを行いたい。

初質問のため、至らないところが多いかと思いますが、よろしくお願いします。

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

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

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

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

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

guest

回答1

0

自己解決

interaction.response を button.response にすることでインタラクションの応答ができました

投稿2022/06/25 10:12

lawliet

総合スコア10

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.51%

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

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

質問する

関連した質問