-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
109 lines (86 loc) · 3.56 KB
/
index.js
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
const Discord = require('discord.js');
const {Player} = require('discord-player');
const fs = require('fs');
const config = require ("./config.json") // your token here
const prefix = "!" // I use this prefix, but you can change if you want
const { Client, GatewayIntentBits } = require ('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent // On discord.com/developers/applications you have to check if the permission it's on
],
});
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
console.log(client.commands);
client.on('ready', () => {
console.log(`Bot online! ${client.users.cache.size} users!, in ${client.guilds.cache.size} servers!`);
client.user.setActivity(`Rawwr!! Translate ${client.guilds.cache.size} SERVERS THAT I AM`);
});
client.on('ready', () => {
console.log(`HADES!Bot connected as ${client.user.tag}`);
});
client.on('messageCreate', async (msg) => {
if(msg.content === prefix + 'teste'){
await msg.channel.send('teste')
}
});
client.on('messageCreate', async (msg) => {
if(msg.content === prefix + 'ping'){
await msg.channel.send(`Pong! 🏓 ${Math.round(client.ws.ping)} ms`)
}
});
const player = new Player(client);
player.on('connectionCreate', (queue) => { // this command was made by Gabriel Tanner to fix a problem to play music on channel
queue.connection.voiceConnection.on('stateChange', (oldState, newState) => {
const oldNetworking = Reflect.get(oldState, 'networking');
const newNetworking = Reflect.get(newState, 'networking');
const networkStateChangeHandler = (oldNetworkState, newNetworkState) => {
const newUdp = Reflect.get(newNetworkState, 'udp');
clearInterval(newUdp?.keepAliveInterval);
}
oldNetworking?.off('stateChange', networkStateChangeHandler);
newNetworking?.on('stateChange', networkStateChangeHandler);
});
});
player.on('error', (queue, error) => {
console.log(`[${queue.guild.name}] Error on queue😳 ${error.message}`);
});
player.on('connectionError', (queue, error) => {
console.log(`[${queue.guild.name}] Error on queue😳 ${error.message}`);
});
player.on('trackStart', (queue, track) => {
queue.metadata.send(`▶ | Started to play **${track.title}** 🎶 **${queue.connection.channel.name}**!`);
});
player.on('trackAdd', (queue, track) => {
queue.metadata.send(`🎶 | Track **${track.title}** queued!`);
});
player.on('botDisconnect', queue => {
queue.metadata.send(' RAWWr! I was disconnected on voice chat...');
});
player.on('channelEmpty', queue => {
queue.metadata.send('Nobody is in the voice channel, leaving...');
});
player.on('queueEnd', queue => {
queue.metadata.send('Queue finished!');
});
client.on('messageCreate', async (msg) => {
if (msg.content === '!deploy'){ // command deploy to use slash commands
await msg.guild.commands
.set(client.commands)
.then(() => {
msg.reply('Deployed!');
})
.catch(err => {
msg.reply('Not deploy! :/ ');
console.error(err)
});
}
});
client.login(config.token);