discorddiscord.js

How to create an emoji?


Any idea on how to create an emoji on discord.js v14. The docs are not really helping?

Used to do this in discord.js V13

const emoji = await message.guild.emojis.create(emojiLink, emojiName);

But it doesn't work anymore, now it throws the following error:

[ANTI-CRASH] Unhandled Rejection: TypeError [ReqResourceType]: The resource must be a string, Buffer or a valid file stream.

The code (partially) in case it is any kind of help:

 const modifiedLink = emojiURL.replace(substringToRemove, "");
    const modifiedLink2 = substringToAdd + modifiedLink + substringToAddEnd;
    const modifiedLink3 = modifiedLink2.replace(ReplaceEmote, "emote")?.trim();

    console.log(modifiedLink3);

    // Use the temporary file to create a new custom emoji
    const emoji = await message.guild.emojis.create(modifiedLink3, emojiName);

Solution

  • Looking at the documentation you can see there is only one argument: options

    Parameter Type Description
    options GuildEmojiCreateOptions Options for creating the emoji

    There are also 2 examples stating how to use the method:

    // Create a new emoji from a URL
    guild.emojis.create({ attachment: 'https://i.imgur.com/w3duR07.png', name: 'rip' })
      .then(emoji => console.log(`Created new emoji with name ${emoji.name}!`))
      .catch(console.error);
    
    // Create a new emoji from a file on your computer
    guild.emojis.create({ attachment: './memes/banana.png', name: 'banana' })
      .then(emoji => console.log(`Created new emoji with name ${emoji.name}!`))
      .catch(console.error);
    

    reference