-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
81 lines (56 loc) · 1.78 KB
/
main.js
File metadata and controls
81 lines (56 loc) · 1.78 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
const Discord = require('discord.js'),
embed = require( "./utils/embed" ),
fs = require( "fs" );
const DisTubeHandler = require( "./utils/distube" );
require( "dotenv" ).config();
const intents = new Discord.Intents([
Discord.Intents.NON_PRIVILEGED,
"GUILD_MEMBERS"
]);
const client = new Discord.Client({ ws: { intents } });
client.commands = new Discord.Collection();
client.distube = new DisTubeHandler( client );
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 );
}
client.on("ready", () => {
client.user.setActivity(
"Lol: Wild Rift!",
{ type: "PLAYING" }
);
return console.log(
`Bot has started as ${ client.user.tag }`
)
});
client.on("message", ( message ) => {
const file = fs.readFileSync( __dirname + "/config.json" ),
config = JSON.parse( file );
if ( !message.content.startsWith( config.prefix ) )
return;
if ( message.author.bot ) return;
const args = getArgs( message, config );
if ( args ) tryCommand( client, message, args );
});
function getArgs( message, config ) {
const args = message.content.slice(
config.prefix.length
).trim().split( / +/g );
return {
command: args.shift().toLowerCase(),
body: args.join( " " )
}
}
function tryCommand( client, message, { command, body } ) {
if ( !client.commands.has( command )) return;
try {
client.commands.get( command ).execute( client, message, body );
} catch ( error ) {
return embed( message, "RED", "Error!", error );
}
}
client.distube.listen();
client.login( process.env.TOKEN );