Discord.js v14でEmbed付きボタンでボタンが押された際の処理

実現したいこと

Discord.jsでMinecraftコミュニティのロール申請Botを作っています。
ユーザーが、/registerを実行すると、Embedとボタンが表示され、ボタンを押すとモーダルウィンドウを表示する

発生している問題・エラーメッセージ

[InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred.

該当のソースコード

js

1const { SlashCommandBuilder, EmbedBuilder, Message, ButtonBuilder, ButtonStyle, ModalBuilder, TextInputBuilder, ActionRowBuilder, TextInputStyle, ActionRow} = require('discord.js');2 3module.exports = {4 data: new SlashCommandBuilder()5 .setName('register')6 .setDescription('ロール申請を行います'),7 8 async execute(interaction) {9 // 確認の情報10 const embed = new EmbedBuilder()11 .setColor('Green')12 .setTitle('ロール申請の注意点')13 .setDescription("ロール申請を行う前に次のことを済ませているかご確認ください。\n\n✅ [利用規約]()は読みましたか?\n✅ Discordのアイコンは変更しましたか?\n✅ SNS(Twitterなど)とDiscordを[連携](https://support.discord.com/hc/ja/articles/8063233404823-%E6%8E%A5%E7%B6%9A-%E3%83%AA%E3%83%B3%E3%82%AF%E3%81%95%E3%82%8C%E3%81%9F%E3%83%AD%E3%83%BC%E3%83%AB-%E3%82%B3%E3%83%9F%E3%83%A5%E3%83%8B%E3%83%86%E3%82%A3%E3%83%A1%E3%83%B3%E3%83%90%E3%83%BC)していますか?\n✅ あなたは13歳以上ですか?\n\n**確認ができた場合は下の「申請」ボタンから申請を行ってください。**")14 .setAuthor({name:'Role Authenticator',iconURL:'https://cdn.discordapp.com/avatars/1099893089151230052/b8363d5a2cfa6ea8645a145befd5b9cf.png'})15 .setTimestamp()16 17 const err_late = new EmbedBuilder()18 .setColor("Red")19 .setTitle(":x:申請が取り消されました")20 .setDescription("再度\`/register\`コマンドを使用して申請を作成してください")21 .setTimestamp()22 23 // ボタンクラスの作成24 const confirm = new ButtonBuilder({25 custom_id: 'send',26 style: ButtonStyle.Success,27 label: 'ロール申請',28 });29 30 // ボタンクラスの登録31 const register = new ActionRowBuilder()32 .addComponents(confirm);33 34 const response = await interaction.update({embeds: [embed], components:[register],ephemeral: true}); 35 const collectorFilter = i => i.user.id === interaction.user.id;36 37 try {38 const confirmation = await response.awaitMessageComponent({ filter: collectorFilter, time: 600_000 });39 40 if (confirmation.customId === 'send') {41 const modal = new ModalBuilder()42 .setCustomId('confirmmodal')43 .setTitle('申請の送信');44 const mcid = new TextInputBuilder()45 .setCustomId('mcid')46 .setLabel('MCID')47 .setStyle(TextInputStyle.Short);48 const jebe = new TextInputBuilder()49 .setCustomId('jebe')50 .setLabel('統合版かJava版どちらか記入してください')51 .setStyle(TextInputStyle.Short);52 const sns = new TextInputBuilder()53 .setCustomId('sns')54 .setLabel('SNS(Twitter)などのリンクがある場合は貼ってください')55 .setStyle(TextInputStyle.Paragraph);56 57 const row1 = new ActionRowBuilder().addComponents(mcid);58 const row2 = new ActionRowBuilder().addComponents(jebe);59 const row3 = new ActionRowBuilder().addComponents(sns);60 modal.addComponents(row1,row2,row3);61 62 await interaction.showModal(modal);63 const filter = (mInteraction) => mInteraction.customId === 'sendmod';64 interaction.awaitModalSumbit({filter,time:60000})65 }66 } catch (e) {67 console.log(e);68 }69 }70};71

試したこと

ボタンクリック時にエラーになるようでinteractionを延期させたりしてみましたができませんでした。(このエラーについて調べてみたのですが解決方法が見つかりませんでした...)

補足情報(FW/ツールのバージョンなど)

Discord.js v14を使用しています。(また、今回はファイル分けでBotログイン用のindex.jsが別にあります。)

コメントを投稿

0 コメント