GuildCreate and GuildDelete iconURL when null

Hello, I'm trying to make my bot log which servers it joined/left with name, icon and id but it creates an error and doesn't post the embed when the server doesn't have an iconURL guild.iconURL returns:
iconURL(options = {}) {
return this.icon && this.client.rest.cdn.icon(this.id, this.icon, options);
}
iconURL(options = {}) {
return this.icon && this.client.rest.cdn.icon(this.id, this.icon, options);
}
Anyone how how to handle this case and make the bot post the embed without the iconurl when the server doesn't have an icon?
3 Replies
d.js toolkit
d.js toolkit15mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
d.js docs
d.js docs15mo ago
method Guild#iconURL() The URL to this guild's icon.
Robelo06
Robelo06OP15mo ago
I don't know what you mean. I already call the function but I need to know how to handle that case
client.on(Events.GuildCreate, guild => {
const joinChannel = client.channels.cache.get('CHANNELID');
const joinembed = new EmbedBuilder()
.setColor(0x00ff00)
.setTitle('Joined a new Guild')
.setThumbnail(`${guild.iconURL({ size: 2048 }) }`)
.addFields(
{ name: 'Server name', value: `${guild.name}` },
{ name: '\u200B', value: '\u200B' },
{ name: 'Members', value: `${guild.memberCount}`, inline: true },
{ name: 'ID', value: `${guild.id}`, inline: true },
{ name: 'GuildsCount', value: `${client.guilds.cache.size}`, inline: true },
)
.setTimestamp();
joinChannel.send({embeds:[joinembed]});
client.on(Events.GuildCreate, guild => {
const joinChannel = client.channels.cache.get('CHANNELID');
const joinembed = new EmbedBuilder()
.setColor(0x00ff00)
.setTitle('Joined a new Guild')
.setThumbnail(`${guild.iconURL({ size: 2048 }) }`)
.addFields(
{ name: 'Server name', value: `${guild.name}` },
{ name: '\u200B', value: '\u200B' },
{ name: 'Members', value: `${guild.memberCount}`, inline: true },
{ name: 'ID', value: `${guild.id}`, inline: true },
{ name: 'GuildsCount', value: `${client.guilds.cache.size}`, inline: true },
)
.setTimestamp();
joinChannel.send({embeds:[joinembed]});
ah It says that the guild icon exists I made it log 'No' when there is an iconURL and 'Yes' when there isn't. I tried with a server that has an icon and it logged no I tried with a server that does not have an icon and it still logged no
client.on(Events.GuildCreate, guild => {
const joinChannel = client.channels.cache.get('CHANNELID');
if (!guild.icon) {
console.log('Yes'); ///No icon url
}
if (guild.icon) {
console.log('No'); //Icon url
}
const joinembed = new EmbedBuilder()
.setColor(0x00ff00)
.setTitle('Joined a new Guild')
.setThumbnail(`${guild.iconURL({ size: 2048 }) }`)
.addFields(
{ name: 'Server name', value: `${guild.name}` },
{ name: '\u200B', value: '\u200B' },
{ name: 'Members', value: `${guild.memberCount}`, inline: true },
{ name: 'ID', value: `${guild.id}`, inline: true },
{ name: 'GuildsCount', value: `${client.guilds.cache.size}`, inline: true },
)
.setTimestamp();
joinChannel.send({embeds:[joinembed]});
if (bannedGuilds.includes(interaction.guild.id)) {
guild.leave();
joinChannel.send('This Guild is blacklisted. The Bot left the guild.');
}
});
client.on(Events.GuildCreate, guild => {
const joinChannel = client.channels.cache.get('CHANNELID');
if (!guild.icon) {
console.log('Yes'); ///No icon url
}
if (guild.icon) {
console.log('No'); //Icon url
}
const joinembed = new EmbedBuilder()
.setColor(0x00ff00)
.setTitle('Joined a new Guild')
.setThumbnail(`${guild.iconURL({ size: 2048 }) }`)
.addFields(
{ name: 'Server name', value: `${guild.name}` },
{ name: '\u200B', value: '\u200B' },
{ name: 'Members', value: `${guild.memberCount}`, inline: true },
{ name: 'ID', value: `${guild.id}`, inline: true },
{ name: 'GuildsCount', value: `${client.guilds.cache.size}`, inline: true },
)
.setTimestamp();
joinChannel.send({embeds:[joinembed]});
if (bannedGuilds.includes(interaction.guild.id)) {
guild.leave();
joinChannel.send('This Guild is blacklisted. The Bot left the guild.');
}
});
wth it returns null ah, maybe because iconURL instead of icon icon returns null yeah, sorry XD thanks for your help
Want results from more Discord servers?
Add your server