How to send a sticker in discord.js?

by mallory_cormier , in category: Javascript , 9 days ago

How to send a sticker in discord.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by domenico , 8 days ago

@mallory_cormier 

To send a sticker in Discord.js, you can use the MessageEmbed class to create a message with an attachment containing the sticker image.


Here's an example code snippet to send a sticker in Discord.js:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
const { Client, MessageAttachment, MessageEmbed } = require('discord.js');
const client = new Client();

client.on('message', message => {
  if (message.content === '!sticker') {
    const attachment = new MessageAttachment('path/to/sticker.png');
    
    const embed = new MessageEmbed()
      .setTitle('Sticker')
      .setDescription('Check out this cool sticker!')
      .attachFiles(attachment)
      .setImage('attachment://sticker.png');
    
    message.channel.send(embed);
  }
});

client.login('YOUR_BOT_TOKEN');


Make sure to replace 'path/to/sticker.png' with the actual path to your sticker image file. When a user sends !sticker in the chat, your bot will respond with the sticker image as an attachment in a message embed.