Waiting for the caching state from discord client

This commit is contained in:
Dennis Heinrich 2024-04-28 21:15:19 +02:00
parent d08bf65ef5
commit ef9d2054d7
2 changed files with 112 additions and 101 deletions

View file

@ -46,17 +46,21 @@ client.once(Events.ClientReady, readyClient => {
});
});
event.on('verification:success', (authenticationObject, internetProtocolAddress) => {
console.log(authenticationObject.guildId)
console.log(authenticationObject.userId)
let guild = client.guilds.cache.get(authenticationObject.guildId);
console.log(guild)
let member = guild.members.cache.get(authenticationObject.userId);
console.log(member)
if(member) {
member.roles.add(verifiedRoleId);
}
client.on('ready', () => {
console.log('Discord is connected and cached');
event.emit('discord:ready');
});
event.on('verification:success', (authenticationObject, internetProtocolAddress) => {
client.guilds.fetch().then(async () => {
const guild = await client.guilds.fetch(authenticationObject.guildId);
const member = await guild.members.fetch(authenticationObject.userId);
const role = guild.roles.cache.get(verifiedRoleId);
if (role && member) {
member.roles.add(role)
.then(() => {
console.log(`Role ${role.name} has been added to ${member.user.tag}`)
let embedBuilder = new EmbedBuilder();
embedBuilder.setTitle('Verifizierung abgeschlossen');
embedBuilder.setFields([
@ -66,8 +70,13 @@ event.on('verification:success', (authenticationObject, internetProtocolAddress)
{ name: 'IP-Informationen', value: `[Informationen anzeigen](https://ipinfo.io/${internetProtocolAddress})`, inline: false },
{ name: 'User-ID', value: `${member.id}`, inline: false },
]);
client.channels.cache.get(channelLogsId).send({embeds: [embedBuilder]});
})
.catch(console.error);
} else {
console.log('Role or member not found');
}
});
});
client.login(discordToken);

View file

@ -6,6 +6,7 @@ const event = require('../events/index').eventBus;
const blacklist = require('../network/blacklist');
const database = require('../database/index');
event.on('discord:ready', () => {
// This will load the blacklist and start the webserver when it's done
blacklist.loadBlacklist().then(blacklist => {
console.log('Network-Blacklist has been loaded')
@ -92,3 +93,4 @@ blacklist.loadBlacklist().then(blacklist => {
console.log(`Webserver is available on http://localhost:${port}`)
})
});
});