Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
86
rated 0 times [  87] [ 1]  / answers: 1 / hits: 8266  / 6 Years ago, mon, april 30, 2018, 12:00:00

The error happens at if(serversInfo[user.guild.id].modlog_enabled



Also, let serversInfo = JSON.parse(fs.readFileSync('./data/servers.json', 'utf8'));
if that helps.



client.on('guildBanAdd', user => {
if (serversInfo[user.guild.id].modlog_enabled == true && serversInfo[user.guild.id].modlog_channel !== null) {
var d = Date.now()
d = new Date(d)
d = d.getMonth() + 1 + '/' + d.getDate() + '/' +
d.getFullYear() + ' ' +
(d.getHours() > 12 ? d.getHours() - 12 : d.getHours()) + ':' + d.getMinutes() + ' ' + (d.getHours() >= 12 ? 'PM' : 'AM')

client.channels
.get(serversInfo[user.guild.id].modlog_channel)
.send(`${user}**//**${user.id} was banned on **${d}**.`)

} else if (err) {
console.log(err)
}
})


I have tried to use just guild.id but that didn't seem to work as I would get an error of guild is not defined. modlog_enabled has been set to true in the .json file but it doesn't see it. My other events work fine when checking modlog_enabled.


More From » node.js

 Answers
16

client.on('guildBanAdd') returns a guild and a user, not both together.

And the user is not on the guild anymore, so using user.guild wouldn't make much sense.



client.on('guildBanAdd', (guild, user) => {

if(serversInfo[guild.id].modlog_enabled == true && serversInfo[guild.id].modlog_channel !== null){
var d = Date.now();
d = new Date(d);
d = (d.getMonth()+1)+'/'+d.getDate()+'/'+d.getFullYear()+' '+(d.getHours() > 12 ? d.getHours() - 12 : d.getHours())+':'+d.getMinutes()+' '+(d.getHours() >= 12 ? PM : AM);

client.channels.get(serversInfo[guild.id].modlog_channel).send(`${user}**//**${user.id} was banned on **${d}**.`)
} else if (err){console.log(err)}

});

[#13737] Saturday, April 28, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rocky

Total Points: 316
Total Questions: 108
Total Answers: 110

Location: Mali
Member since Sat, Feb 12, 2022
2 Years ago
;