Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the bot send personalized emojis?

Well, I'm currently using the emoji :x:, but on my server I have an emoji called :superbotxemoji: I just don't know how I get my bot to use it

My code:

const Discord = require('discord.js');

module.exports = {
 name: 'say',
 description: 'say',
 execute(message, args) {
  const { prefix, token } = require('../config.json');

  if (!message.member.hasPermission('ADMINISTRATOR'))
   return message.channel.send({
    embed: {
     color: 16777201,
     description: `:x: | ${message.author}, You are not allowed to use this command.`,
     footer: {
      text: `   | Required permission: ADMINISTRATOR`,
     },
    },
   });

  if (!args.length)
   return message.channel.send({
    embed: {
     color: 16777201,
     description: `:x: | ${message.author}, You need to put a message.`,
     footer: {
      text: `   | Example: !say hello`,
     },
    },
   });

  const sayMessage = args.join(' ');
  message.delete({ timeout: 1 });
  message.channel.send(sayMessage);
 },
};
like image 698
SrVertigu Avatar asked Oct 22 '25 07:10

SrVertigu


1 Answers

There is actually a very detailed explanation from the official discord.js guide which you can find here, although I'll try to paraphrase it.

To send a custom emoji, you must get that emoji's unique ID. To find that, you must send the emote in discord with a backslash in front of it; essentially escaping the emoji.

Escape

This will result in the emojis unique ID in this format: <:emoji-name:emoji-id>

Format

If you paste this special string into a message, the bot will send the emoji. However, the emoji must be from a guild the bot is part of.

Emoji

On the other hand, there's another very easy way to get an emoji using the client.emojis.cache collection and the .find() method.

client.emojis.cache.find(emoji => emoji.name === '<name of emoji>')

.find()

This method will also make it possible to send custom emojis, however, this time you can find them by name. Be careful, if there are more than one emojis by the given name, it will not work.

A way to bypass this problem would be looking at a guild.emojis.cache collection. This way the amount of possible duplicate emojis would be narrowed down.

like image 145
Lioness100 Avatar answered Oct 23 '25 20:10

Lioness100



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!