#GuildCreate and GuildDelete iconURL when null

19 messages · Page 1 of 1 (latest)

edgy umbra
#

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);
}

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?

foggy riverBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • 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!
  • Marked as resolved by OP
tidal sparrow
#

It’s a function. Call it

vestal dirgeBOT
edgy umbra
tidal sparrow
#

You do? What you wrote doesn’t seem like you did, you merely accessed it as a property

edgy umbra
#
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]});
edgy umbra
tidal sparrow
#

What says that? And no need to reply (and ping) me with every message when we‘re literally the only members in this thread

edgy umbra
#

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

tidal sparrow
#

And where is that code doing that? You‘ve been here long enough that you should know by now that you should provide the code that doesn’t do what you expect it to do by now. Not other parts of the code that aren’t those you have issues with atm

edgy umbra
#
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.');
    }
});
tidal sparrow
edgy umbra
#

wth it returns null

#

ah, maybe because iconURL instead of icon

#

icon returns null

tidal sparrow
edgy umbra
#

yeah, sorry XD