現在discord botをpythonで作成しています。
interactions.pyを利用して、コンポーネント(ボタンフォーム)の付いたメッセージを送信、ボタンが押下されるとモーダルを表示し、それと同時にメッセージを編集しようとしましたが、うまく動作しません。
(動作しないのはなんとなくわかりますが…)
これらを解決する方法をご存じであればご教授いただけると幸いです。
ソースコード(一部)
py
1import discord 2import interactions 3 4@bot.command( 5 name="questionnaire", 6 description="アンケート" 7) 8async def com_q(ctx): 9 global message 10 message = await ctx.send( 11 "どちらがいいですか?\nモーダルを開きます", 12 components=[ 13 interactions.Button(style=interactions.ButtonStyle.SUCCESS, label="OK!", custom_id="q_acc"), 14 interactions.Button(style=interactions.ButtonStyle.DANGER, label="やめておく", custom_id="q_den") 15 ], 16 ephemeral=True 17 ) 18 19@bot.component("q_acc") 20async def button_res_q_acc(ctx): 21 modal = interactions.Modal( 22 title="フォーム", 23 custom_id="mod_que", 24 components=[ 25 interactions.TextInput( 26 style=interactions.TextStyleType.SHORT, 27 label="1. or 2.", 28 custom_id="mod_que_ans_1", 29 min_length=1, 30 max_length=20 31 ), 32 interactions.TextInput( 33 style=interactions.TextStyleType.PARAGRAPH, 34 label="その他に何かあれば入力してください", 35 custom_id="mod_que_ans_2", 36 required=False 37 ) 38 ], 39 ) 40 await ctx.edit("送信済み",components=None) 41 await ctx.popup(modal)
エラーメッセージ
Interaction has already been acknowledged. Task exception was never retrieved future: <Task finished name='Task-19' coro=<button_res_q_acc() done, defined at /root/bot/bot3_pre.py:116> exception=LibraryException("An error occurred:\nInteraction has already been acknowledged., with code '40060' and severity '40'")> Traceback (most recent call last): File "/root/bot/bot3_pre.py", line 138, in button_res_q_acc await ctx.popup(modal) File "/usr/local/lib/python3.10/dist-packages/interactions/client/context.py", line 286, in popup await self._client.create_interaction_response( File "/usr/local/lib/python3.10/dist-packages/interactions/api/http/interaction.py", line 227, in create_interaction_response return await self._req.request( File "/usr/local/lib/python3.10/dist-packages/interactions/api/http/request.py", line 174, in request raise LibraryException( interactions.api.error.LibraryException: An error occurred: Interaction has already been acknowledged., with code '40060' and severity '40'
あなたの回答
tips
プレビュー