-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.cjs
226 lines (184 loc) · 6.18 KB
/
app.cjs
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
require('dotenv').config();
const {REST} = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { Client, Intents, Collection, Collector } = require('discord.js');
const { Player } = require("discord-player")
const {RandomWordsArray} = require('./MAO.cjs');
const fs = require('fs');
const path = require('path');
const { channel } = require('diagnostics_channel');
const { spoiler } = require('@discordjs/builders');
const { default: queue } = require('./commands/queue.cjs');
const DiscordUtility = require("utils-discord");
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_VOICE_STATES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS],
partials: ['MESSAGE', 'CHANNEL', 'REACTION']
});
// List of all commands
const commands = [];
client.commands = new Collection();
const commandsPath = path.join(__dirname, "commands"); // E:\yt\discord bot\js\intro\commands
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.cjs'));
for(const file of commandFiles)
{
const filePath = path.join(commandsPath, file);
const command = require(filePath);
client.commands.set(command.data.name, command);
commands.push(command.data.toJSON());
}
client.utils = DiscordUtility;
// Add the player on the client
client.player = new Player(client, {
ytdlOptions: {
quality: "highestaudio",
highWaterMark: 1 << 25
},
})
client.on("ready", () => {
// Get all ids of the servers
const guild_ids = client.guilds.cache.map(guild => guild.id);
console.log("I am ready")
const rest = new REST({version: '9'}).setToken(process.env.DISCORD_BOT_TOKEN);
for (const guildId of guild_ids)
{
rest.put(Routes.applicationGuildCommands(process.env.CLIENT_ID, guildId),
{body: commands})
.then(() => console.log('Successfully updated commands for guild ' + guildId))
.catch(console.error);
}
});
client.on("interactionCreate", async interaction => {
if(!interaction.isCommand()) return;
const command = client.commands.get(interaction.commandName);
if(!command) return;
try
{
await command.execute({client, interaction});
}
catch(error)
{
console.error(error);
await interaction.reply({content: "There was an error executing this command"});
}
});
client.login(process.env.DISCORD_BOT_TOKEN);
//Timer
let PREFIX = '/'
client.on('message', message => {
if(message.content.startsWith(PREFIX) && message.content.endsWith("mao")){
let duration = 45;
let getTime = "Timer: " + duration
let botMessage = message.channel;
botMessage.send(getTime);
let interval = setInterval(() => {
duration--;
botMessage.lastMessage.edit("Timer: " + duration)
if(duration <= 0) {
clearInterval(interval);
botMessage.lastMessage.edit("Timern är klar")
}
}, 1000)
function getRandomWord(max){
return Math.floor(Math.random()* max)
}
// let forLength = 5;
// let Words = ""
let DM = message.author;
// for(let i = 0; i < forLength; i++) {
// Words += RandomWordsArray[getRandomWord(12)] + '\n'
// }
// DM.send(`||${Words}||`)
const Word1 = RandomWordsArray[getRandomWord(331)]
const Word2 = RandomWordsArray[getRandomWord(331)]
const Word3 = RandomWordsArray[getRandomWord(331)]
const Word4 = RandomWordsArray[getRandomWord(331)]
const Word5 = RandomWordsArray[getRandomWord(331)]
const Word6 = RandomWordsArray[getRandomWord(331)]
const Word7 = RandomWordsArray[getRandomWord(331)]
const Word8 = RandomWordsArray[getRandomWord(331)]
const Word9 = RandomWordsArray[getRandomWord(331)]
const Word10 = RandomWordsArray[getRandomWord(331)]
const Word11 = RandomWordsArray[getRandomWord(331)]
const Word12 = RandomWordsArray[getRandomWord(331)]
const Word13 = RandomWordsArray[getRandomWord(331)]
const Word14 = RandomWordsArray[getRandomWord(331)]
const Word15 = RandomWordsArray[getRandomWord(331)]
const Word16 = RandomWordsArray[getRandomWord(331)]
const Word17 = RandomWordsArray[getRandomWord(331)]
const Word18 = RandomWordsArray[getRandomWord(331)]
const Word19 = RandomWordsArray[getRandomWord(331)]
const Word20 = RandomWordsArray[getRandomWord(331)]
DM.send(`
\n
**Ord1:**
||${Word1}||
**Ord2: **
||${Word2}||
**Ord3: **
||${Word3}||
**Ord4: **
||${Word4}||
**Ord5: **
||${Word5}||
**Ord6: **
||${Word6}||
**Ord7: **
||${Word7}||
**Ord8: **
||${Word8}||
**Ord9: **
||${Word9}||
**Ord10: **
||${Word10}||
**Ord11: **
||${Word11}||
**Ord12: **
||${Word12}||
**Ord13: **
||${Word13}||
**Ord14: **
||${Word14}||
**Ord15: **
||${Word15}||
**Ord16: **
||${Word16}||
**Ord17: **
||${Word17}||
**Ord18: **
||${Word18}||
**Ord19: **
||${Word19}||
**Ord20: **
||${Word20}||
`);
}
})
//restart bot
client.on('message', message => {
if(message.content.startsWith(PREFIX) && message.content.endsWith("restart")) {
if(message.author.id !== '236574009641140226') return false;
resetBot();
message.channel.send("Omstartad")
}
})
client.on('message', message =>{
const answers = [
"100%",
"Absolut",
"Ja",
"Nej",
"Absolut inte",
"Aldrig"
]
if(message.content.startsWith("/8ball")){
function getRandomAnswer(max){
return Math.floor(Math.random()* max)
}
let randomAnswer = answers[getRandomAnswer(6)]
message.channel.lastMessage.reply(randomAnswer)
}
})
function resetBot(){
client.destroy();
client.login(process.env.DISCORD_BOT_TOKEN);
}