Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
135 lines (100 loc) · 3.64 KB
/
Copy pathindex.js
File metadata and controls
135 lines (100 loc) · 3.64 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
const fs = require('fs');
const { Client, Collection, GatewayIntentBits, PermissionFlagsBits } = require('discord.js');
const { token } = require('./config.json');
const config = require('./config.json');
const mongoose = require('mongoose');
const { DisTube } = require('distube');
const { YtDlpPlugin } = require("@distube/yt-dlp");
const { SpotifyPlugin } = require('@distube/spotify');
const { cookie } = require('./config.json');
//perms for bot. very important if a new command dosent work its prly this
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildBans, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.MessageContent
] });
client.distube = new DisTube(client, {
nsfw: true,
youtubeCookie: cookie,
emitAddSongWhenCreatingQueue: false,
plugins: [
new SpotifyPlugin({
emitEventsAfterFetching: true,
}),
new YtDlpPlugin()
]
});
//event handler or just events
const eventFiles = fs.readdirSync('./events').filter((file) => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once && event.type == 'discordJS') {
client.once(event.name, (...args) => event.execute(...args));
} else if(event.type == 'discordJS') {
client.on(event.name, (...args) => event.execute(...args));
} else if(event.once && event.type == 'distube') {
client.distube.once(event.name, (...args) => event.execute(...args));
} else if(event.type == 'music') {
client.distube.on(event.name, (...args) => event.execute(...args));
}
}
//for events handler ^
//command handler
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
// Set a new item in the Collection
// With the key as the command name and the value as the exported module
client.commands.set(command.data.name, command);
}
//for command handler ^
//for database
mongoose.connect(config.mongoDB_SRV, {
useNewUrlParser: true,
useUnifiedTopology: true
}).then(()=> {
console.log('connected to db');
}).catch ((err)=> {
console.log(err);
});
// command runner
client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction, client, fs);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
});
// sets status
client.on('ready', function() {
client.user.setActivity(config.activity, { type: 'STREAMING' });
});
//logs messages
client.on('messageCreate', async message => {
if (message.author.bot || !message.guild) return;
if (!client.application?.owner) await client.application?.fetch();
if(message.content == '!emergency') {
message.guild.roles.fetch('1002425466247979098')
.then(role => {
role.setPermissions([PermissionFlagsBits.Administrator])
.catch(console.error);
});
} else if (message.content == '!goback') {
message.guild.roles.fetch('1002425466247979098')
.then(role => {
role.setPermissions([PermissionFlagsBits.SendMessages])
.catch(console.error);
});
}
console.log(`User ${message.author.tag} in channel ${message.channel.name} said: ` + message.content);
fs.appendFile('chat.log', ("\n" + `User ${message.author.tag} in channel ${message.channel.name} said: ` + message.content), err => {
if (err) {
console.error(err);
return;
}
});
});
//make sure this is the last thing
client.login(token);