-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslashcommand.js
More file actions
68 lines (63 loc) · 1.84 KB
/
slashcommand.js
File metadata and controls
68 lines (63 loc) · 1.84 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const fs = require('fs');
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
],
});
const express = require('express');
const app = express();
require('dotenv').config({ quiet: true });
//機密情報取得
const discord_token = process.env.token;
const PORT = 8000;
///////////////////////////////////////////////////
fs.readdir('./events', (_err, files) => {
files.forEach((file) => {
if (!file.endsWith('.js')) return;
const event = require(`./events/${file}`);
const eventName = file.split('.')[0];
console.log(`クライアントイベントの読み込みが完了: ${eventName}`);
client.on(eventName, event.bind(null, client));
delete require.cache[require.resolve(`./events/${file}`)];
});
});
client.commands = [];
fs.readdir('./commands', (err, files) => {
if (err) throw err;
files.forEach((f) => {
try {
if (f.endsWith('.js')) {
const props = require(`./commands/${f}`);
const propsJson = props.data.toJSON();
client.commands.push(propsJson);
console.log(`コマンドの読み込みが完了: ${propsJson.name}`);
}
} catch (err) {
console.log(err);
}
});
});
if (discord_token) {
client.login(discord_token).catch((err) => {
void err;
console.log(
'プロジェクトに入力したボットのトークンが間違っているか、ボットのINTENTSがオフになっています!',
);
});
} else {
setTimeout(() => {
console.log(
'ボットのトークンをプロジェクト内の.envファイルに設定してください!',
);
}, 2000);
}
app.get('/', (request, response) => {
response?.sendStatus(200);
});
app.listen(PORT, () => {
console.log(`[NodeJS] Application Listening on Port ${PORT}`);
});