discord.jsv13でslashcommandを作っているのですがエラーが発生して登録することができません。
エラーメッセージ Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'commands')
該当のソースコード
js
const { Client, Intents, Interaction } = require('discord.js'); const client = new Client({intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_MESSAGES]}); const { MessageActionRow, MessageButton, MessageEmbed } = require('discord.js');const { REST } = require('@discordjs/rest');const { Routes } = require('discord-api-types/v9');const fs = require('node:fs');const token = '自分のトークン'const { BUILDER } = require('@discordjs/builders');const { info } = require('node:console');const commands = [];const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));const { SlashCommandBuilder } = require('@discordjs/builders');// Place your client and guild ids hereconst clientId = 'id';const guildId = 'id'; for (const file of commandFiles) { const command = require(`./commands/${file}`); commands.push(command.data.toJSON());} const rest = new REST({ version: '9' }).setToken(token); (async () => { try { console.log('Started refreshing application (/) commands.'); await rest.put( Routes.applicationCommands(clientId), { body: commands }, ); console.log('Successfully reloaded application (/) commands.'); } catch (error) { console.error(error); }})(); client.once('ready', () => { console.log('bot is online!'); }); client.on("ready", async () => { const data = [{ name: "test", description: "test", }]; await client.application.commands.set(data); console.log("Ready!");}); client.on("interactionCreate", async (Interaction) => { if (!Interaction.isCommand()) { return; } if (Interaction.commandName === "test") { await Interaction.reply(" test "); }}); client.login('botのtoken')
補足情報(FW/ツールのバージョンなど)
node v16.13.1
0 コメント