This repository was archived by the owner on Mar 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbotmain.js
More file actions
142 lines (127 loc) · 3.97 KB
/
botmain.js
File metadata and controls
142 lines (127 loc) · 3.97 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
const { Client, GatewayIntentBits, Partials, Collection, EmbedBuilder} = require('discord.js');
let config = require('./config.json')
const studyroom = require('./functions/studyRoom.js');
const join = require('./functions/joinFunc.js')
const dotenv = require('dotenv');
const path = require('path');
const fs = require('fs');
const cron = require('node-cron');
require('date-utils');
dotenv.config();
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.MessageContent,
],
partials: [Partials.Channel],
});
module.exports.client=client;
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
client.commands = new Collection();
module.exports = client.commands;
/*スラッシュコマンド登録*/
client.once("ready", async () => {
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
for (let i = 0; i < command.length; i++) {
client.commands.set(command[i].data.name, command[i]);
}
}
console.log("Ready!");
});
/*実際の動作*/
client.on("interactionCreate", async (interaction) => {
if (!interaction.isCommand()) {
return;
}
const command = interaction.client.commands.get(interaction.commandName);
if (!command) return;
console.log("SlashCommand : "+command.data.name);
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'エラーが発生しました。[サポートサーバー](https://discord.gg/fpEjBHTAqy)にて連絡していただけると助かります。', ephemeral: true });
}
});
/*自習室BOT(VC参加で通知)*/
client.on('voiceStateUpdate', (oldState, newState) => {
studyroom.func(oldState, newState)
})
cron.schedule('0 0 * * *',() => {
studyroom.update();
})
// ステータス設定
cron.schedule('* * * * *',() => {
let date = new Date();
let json = JSON.parse(fs.readFileSync('./studyroom.json', 'utf8'));
let user = json.date.length
let time = Math.floor(date.getTime() / 1000 / 60)%6
let now = json.date.filter(function(item, index){ /*今入ってる人を列挙*/
if (item.now === true ) return true;
});
if(time === 0){
client.user.setPresence({
activities: [{
name: client.guilds.cache.size+"サーバーに導入中"
}],
});
}
else if(time === 1){
client.user.setPresence({
activities: [{
name: user+"人のセーブデータ登録済み"
}],
});
}
else if(time === 2){
client.user.setPresence({
activities: [{
name: "ヘルプ:/help"
}],
});
}
else if(time === 3){
client.user.setPresence({
activities: [{
name: "日別データ:/studydate"
}],
});
}
else if(time === 4){
client.user.setPresence({
activities: [{
name: "週別データ:/studyweek"
}],
});
}
else{
client.user.setPresence({
activities: [{
name: now.length + "人が勉強"
}],
});
}
})
/*BOT参加時*/
client.on('guildCreate', async guild => {
await join.bot(guild)
console.log("ギルド参加処理")
})
/*ユーザー参加時*/
client.on('guildMemberAdd', async member => {
await join.user(member)
console.log("ユーザー参加処理")
})
/*ユーザー退出時*/
client.on('guildMemberRemove', async member => {
await join.rmuser(member)
console.log("ユーザー退出処理")
})
client.login(config.token);