-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-commands.js
More file actions
33 lines (28 loc) · 1.32 KB
/
Copy pathdeploy-commands.js
File metadata and controls
33 lines (28 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const { REST, Routes } = require('discord.js')
const fs = require('fs');
const path = require('path');
const { token, applicationId, guildId } = require('./config.json');
// commandsフォルダからコマンドを取得 .jsファイルのみを取得
const commandFiles = fs.readdirSync(path.join(__dirname, 'commands')).filter(file => file.endsWith('.js'));
// コマンドを登録するためのJsonデータを作成
const commands = commandFiles.map(file => {
const command = require(path.join(__dirname, 'commands', file));
return command.data.toJSON();
});
const rest = new REST({ version: '10' }).setToken(token);
// 即実行関数 定義と同時に実行
(async () => {
try {
// REST APIを使ってコマンドを登録
await rest.put(
// コマンドを登録するAPIのエンドポイントを作成
Routes.applicationCommands(applicationId), // グローバルコマンド
// Routes.applicationGuildCommands(applicationId, guildId), // ギルドコマンド
// コマンドのリストをリクエストボディに設定
{ body: commands },
);
console.log('コマンドを登録しました。');
} catch (error) {
console.error('コマンドの登録中にエラーが発生しました:',error);
}
})();