前提
現在javascriptを利用してDiscordのbotを作成しております。
その中でコマンドを実行した時にモーダルウィンドウを表示する処理を作成しているのですが、discordを開いて
コマンド実行初回時のみ「コマンドを送信中...」というメッセージが消えない事象が発生してしまっています。
一度キャンセルして再度試すとモーダルウィンドウ表示時にメッセージは消えています。
認識としては「interaction.showModal」が実行されたときにコマンドのレスポンスとして返ってきているので、そこでコマンドは実行完了している認識でいます。
実現したいこと
ここに実現したいことを箇条書きで書いてください。
- コマンドを実行しても「コマンドを送信中...」というメッセージが表示されないようにしたい
発生している問題・エラーメッセージ
モーダルウィンドウを表示する処理を作成しているのですが、discordを開いて
コマンド実行初回時のみ「コマンドを送信中...」というメッセージが消えない事象が発生してしまっています。
該当のソースコード
JavaScript
1 2const { Client, GatewayIntentBits, ActionRowBuilder, ModalBuilder, TextInputBuilder, TextInputStyle,InteractionType, ChannelType, Events } = require('discord.js'); 3const { SlashCommandBuilder } = require('@discordjs/builders'); 4const { REST } = require('@discordjs/rest'); 5const { Routes } = require('discord-api-types/v9'); 6//必要なcontentを追加 7const client = new Client({ intents: [ 8 GatewayIntentBits.Guilds, 9 GatewayIntentBits.GuildMembers, 10 GatewayIntentBits.GuildMessages, 11 GatewayIntentBits.MessageContent,] 12}); 13 14//設定ファイル読み込み 15const config_data = require('./config.json'); 16//サーバーID(テスト用) 17const GuildId = config_data.GuildId; 18//botのアプリケーションID 19const ApplicationId = config_data.ApplicationId; 20//botトークン 21const Token = config_data.Token; 22 23// コマンド作成 24const commands = [ 25 //コマンダー登録 26 new SlashCommandBuilder().setName('command_test').setDescription('テストコマンド'), 27].map(command => command.toJSON()); 28 29//コマンド登録処理(bot削除でコマンド削除されるのを確認) 30const rest = new REST({ version: '9' }).setToken(Token); 31rest.put(Routes.applicationGuildCommands(ApplicationId, GuildId), { body: commands }) 32 .then(() => console.log('Successfully registered application commands.')) 33 .catch(console.error); 34 35//起動時処理 36client.once('ready', () => { 37 console.log('Ready!'); 38}); 39 40client.on(Events.InteractionCreate, async interaction => { 41 // コマンドでなかったら弾く 42 if (!interaction.isChatInputCommand()) { 43 return; 44 } 45 if (interaction.commandName === 'command_test') { 46 //コマンダー登録 47 //ウィンドウ作成 48 const modal = new ModalBuilder().setCustomId('commander_regist').setTitle('コマンダー登録'); 49 //入力項目作成 50 const Test1 = new TextInputBuilder() 51 .setCustomId('Test1') 52 .setLabel('Test1') 53 .setStyle(TextInputStyle.Short); 54 const Test2 = new TextInputBuilder() 55 .setCustomId('Test2') 56 .setLabel('Test2') 57 .setStyle(TextInputStyle.Short); 58 //入力項目を追加 59 const ActionRow_1 = new ActionRowBuilder().addComponents(Test1); 60 const ActionRow_2 = new ActionRowBuilder().addComponents(Test2); 61 modal.addComponents(ActionRow_1, ActionRow_2); 62 //ウィンドウ表示 63 await interaction.showModal(modal); 64 } 65}); 66 67//botログイン 68client.login(Token); 69
試したこと
下記を試しましたが、事象は改善しませんでした。
- Discordサーバー内へのbotの入れ直し
- Discord本体の最新化
- スマホ、タブレット、PC版での確認
- モーダルウィンドウ表示前後にinterraction.reply()やinterraction.deferReply()などを利用してメッセージの削除や更新などを試みる
- 下記サイトのサンプルコードを必要箇所のみ丸写しして実行
⇒https://discordjs.guide/interactions/modals.html#building-and-responding-with-modals
補足情報(FW/ツールのバージョンなど)
- discod.js v14
お手数ですがご助力お願いします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/01/09 09:16