forked from RemainNA/auraxis-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessageHandler.js
More file actions
45 lines (42 loc) · 1.67 KB
/
Copy pathmessageHandler.js
File metadata and controls
45 lines (42 loc) · 1.67 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
// This file defines methods for sending messages, and handles errors that occur in that process.
module.exports = {
send: async function(channel, message, context="default", embed=false){
let res = -1;
if(embed && channel.type != 'DM' && !channel.permissionsFor(channel.guild.me).has('EMBED_LINKS')){
channel.send('Please grant the "Embed Links" permission to use this command').then(function(result){
//message successfully sent, no action needed.
}, function(err){
console.log("Error sending embed permission message in context: "+context);
if(typeof(err.message) !== 'undefined'){
console.log(err.message);
}
if(typeof(channel.guild) !== 'undefined'){
console.log(channel.guild.name);
}
});
}
else{
await channel.send(message).then(function(result){
res = result.id;
}, function(err){
console.log("Error sending message in context: "+context);
if(typeof(err.message) !== 'undefined'){
console.log(err.message);
}
if(typeof(channel.guild) !== 'undefined'){
console.log(channel.guild.name);
}
});
}
return res;
},
handleError: function(channel, err, context="default"){
if(typeof(err) == 'string'){
this.send(channel, err, context);
}
else{
console.log("Error returned from function in context: "+context);
console.log(err);
}
}
}