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

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

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

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

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

Q&A

解決済

1回答

2051閲覧

Discord.jsでスラッシュコマンドを登録しようとするとDiscordAPIError[50035]というエラーが出る

Pyrire

総合スコア1

Discord

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

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

0グッド

0クリップ

投稿2023/04/01 11:00

編集2023/04/01 21:19

前提・実現したいこと

Discord.jsでDiscordのBOTを作っています。
Discordのスラッシュコマンドで、チャンネルを移動する機能を作りたかったのですが下のようなエラーが出ました。(DiscordAPIError[50035]:Invalid Form Body)

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

DiscordAPIError[50035]: Invalid Form Body options[2][APPLICATION_COMMAND_OPTIONS_REQUIRED_INVALID]: Required options must be placed before non-required options at SequentialHandler.runRequest(/home/runner/BOTtest/node_modules/@discordjs/rest/dist/index.js:933:15) at process.processTicksAndRejections (node: internal/process/task queues: 95:5) at sync SequentialHandler. queueRequest(/home/runner/BOTtest/node _modules/@discordjs/rest/dist/index. js:712:14) at async REST.request (/home/runner/STARTER/node_modules/@discordjs/rest/dist/index. js:1321:22 at async /home/runner/BOTtest/add_command.js:52: 16 frawError: :{ code: 50035 errors: { options: [Object] }, message: ‘Invalid Form Body’ }, code: 50035, status: 400, method: ‘PUT’, url:’https://discord.com/api/v10/applications/1088266852729368677/guilds/1082959808757502032/commands’ requestBody: {files: undefined, json: [ [Object], [Object] ] } }

該当のソースコード

JavaScript(add_command.js)

1 2const { Client, GatewayIntentBits, Partials, ClientApplication, EmbedBuilder, REST, Routes, SlashCommandBuilde, Collection, Events } = require("discord.js"); 3const token = 4process.env["TOKEN"] 5const CHANNEL_ID = 6process.env["CHANNEL_ID"] 7const clientId = 8process.env["CLIENT_ID"] 9const guildId = 10process.env["GUILD_ID"] 11const fs = require('node:fs'); 12const path = require('node:path'); 13 14 15const client = new Client({ 16 intents: [ 17 GatewayIntentBits.Guilds, 18 GatewayIntentBits.MessageContent, 19 GatewayIntentBits.GuildMessages, 20 ], 21 partials: [ 22 Partials.User, 23 Partials.Channel, 24 Partials.GuildMember, 25 Partials.Message, 26 Partials.Reaction, 27 Partials.GuildScheduledEvent, 28 Partials.ThreadMember, 29 ] 30}); 31const rest = new REST({ version: "10" }).setToken(token); 32 33const commands = []; 34// Grab all the command files from the commands directory you created earlier 35const commandsPath = path.join(__dirname, 'commands'); 36const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js')); 37 38// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment 39for (const file of commandFiles) { 40 const command = require(`./commands/${file}`); 41 commands.push(command.data.toJSON()); 42} 43 44// Construct and prepare an instance of the REST module 45 46 47// and deploy your commands! 48(async () => { 49 try { 50 console.log(`${commands.length}個のアプリケーションコマンドを読み込んでいます`); 51 52 // The put method is used to fully refresh all commands in the guild with the current set 53 const data = await rest.put( 54 Routes.applicationGuildCommands( clientId, guildId ), 55 { body: commands }, 56 ); 57 58 console.log(`${data.length}個のアプリケーションを読み込みました`); 59 } catch (error) { 60 // And of course, make sure you catch and log any errors! 61 console.error(error); 62 } 63})(); 64

JavaScript(index.js)

1 2const TOKEN = 3process.env["TOKEN"] 4const CHANNEL_ID = 5process.env["CHANNEL_ID"] 6const CLIENT_ID = 7process.env["CLIENT_ID"] 8const GUILD_ID = 9process.env["GUILD_ID"] 10const path = require('node:path'); 11const fs = require('node:fs'); 12const { Client, GatewayIntentBits, Partials, ClientApplication, EmbedBuilder, REST, Routes, SlashCommandBuilde, Collection, Events } = require("discord.js"); 13 14const client = new Client({ 15 intents: [ 16 GatewayIntentBits.Guilds, 17 GatewayIntentBits.MessageContent, 18 GatewayIntentBits.GuildMessages, 19 ], 20 partials: [ 21 Partials.User, 22 Partials.Channel, 23 Partials.GuildMember, 24 Partials.Message, 25 Partials.Reaction, 26 Partials.GuildScheduledEvent, 27 Partials.ThreadMember, 28 ] 29}); 30 31const rest = new REST({ version: '10' }).setToken(TOKEN); 32const commandsPath = path.join(__dirname, 'commands'); 33const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js')); 34client.commands = new Collection(); 35 36const http = require("http"); 37http.createServer(function (req, res) { 38 res.write("POWER!!!!!"); 39 res.end(); 40}).listen(8080); 41 42for (const file of commandFiles) { 43 const filePath = path.join(commandsPath, file); 44 const command = require(filePath); 45 if ('data' in command && 'execute' in command) { 46 client.commands.set(command.data.name, command); 47 } else { 48 console.log(`[!]この ${filePath}には"data"か"execute"の値が入ってないそうです `); 49 } 50} 51 52client.on(Events.InteractionCreate, async interaction => { 53 if (!interaction.isChatInputCommand()) return; 54 55 const command = interaction.client.commands.get(interaction.commandName); 56 57 if (!command) { 58 console.error(`[!]この${interaction.commandName}ていうコマンドは存在しないそうです`); 59 return; 60 } 61 62 try { 63 await command.execute(interaction); 64 } catch (error) { 65 console.error(error); 66 if (interaction.replied || interaction.deferred) { 67 await interaction.followUp({ content: "ちょっと何言ってるのか...", ephemeral: true }); 68 } else { 69 await interaction.reply({ content: "ちょっと何言ってるのか...", ephemeral: true }); 70 } 71 } 72}); 73 74//ここから別のやつ〜// 75//Discordにログイン〜 76client.login(TOKEN); 77

試したこと

エラー箇所の変数の型の変更など

補足情報

clientIdやguildIdはReplit側で保存しています。
先日まではこのコードで動いていましたが、今はなぜかエラーを吐くようになっています。
Replitで書いています。下のURLから全体のソースコードに飛べます。
https://replit.com/@LastelPyrire/BOTtest

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

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

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

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

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

Pyrire

2023/04/01 12:14

optionの順番を変えたら帰結できました
guest

回答1

0

自己解決

コマンドのoptionsの順番をtrueから始めてfalseが終わりになるようにしたら解決しました。

投稿2023/04/01 12:19

Pyrire

総合スコア1

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問