前提
Discord.jsで、/helloというスラッシュコマンドをチャンネルに打つと、hello!と返ってくるbotを作っています。
下のリンクの記事のとおりにやっています。
Discord.jsでbotを作ってみよう!(環境準備からスラッシュコマンドであいさつを返すところまで)
実現したいこと
今作っているbotを使って、Discordのチャンネルに/helloというスラッシュコマンドを打つと、hello!と返ってくるようにしたい。
発生している問題・エラーメッセージ
エラーメッセージはないです。連携サービスのところには、「このアプリケーションにはコマンドがありません」と出ています。
該当のソースコード
deploy-commands.js
JavaScript
1const { SlashCommandBuilder } = require('@discordjs/builders'); 2const { REST } = require('@discordjs/rest'); 3const { Routes } = require('discord-api-types/v9'); 4const { clientId, guildId, token } = require('./config.json'); 5const commands = [ 6 new SlashCommandBuilder().setName('hello').setDescription('hello!と返事します!'), 7] 8 .map(command => command.toJSON()); 9const rest = new REST({ version: '9' }).setToken(token); 10rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands }) 11 .then(() => console.log('Successfully registered application commands.')) 12 .catch(console.error);
index.js
JavaScript
1const { Client, Intents } = require('discord.js'); 2const client = new Client({ intents: [Intents.FLAGS.GUILDS] }); 3const { token } = require('./config.json'); 4client.on('ready', () => { 5 console.log(`${client.user.tag}がサーバーにログインしました!`); 6}); 7client.on('interactionCreate', async interaction => { 8 if (!interaction.isCommand()) return; 9 if (interaction.commandName === 'hello') { 10 await interaction.reply('hello!'); 11 } 12}); 13client.login(token);
試したこと
Discordのbotの権限の設定を試行錯誤した。
補足情報(FW/ツールのバージョンなど)
Raspberry Pi OS (Debian系)
node.js v16.15.1
discord.js v13

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/09/19 05:28 編集
2022/09/08 09:13
2022/09/08 09:18
2022/09/19 05:43