user15606442
user15606442

Reputation:

discord.js: How do I replace reactions with buttons in my ticket system?

I am developing my ticketing system in the last time. I saw an update of 'Ticketsbot' and turned curious "how is that possible???, i have never seen that!" this So, can you please help me how can I replace reactions with such buttons.

The part of my code (part which is responsible for reactions):

let embed = new discord.MessageEmbed()
    .setAuthor(`Welcome to your ticket!`)
    .addField('Here you can:', ':one: Report an issue or bug of the server.\n:two: Suggest any idea for the server.\n:three: Report a staff member of the server.')
    .addField('Make sure to be patient, support will be with you shortly.', `<@&837064899322052628>`)
    .setColor('#468DFF')
    .setFooter(`AftNetwork`)

let embed2 = new discord.MessageEmbed()
    .setAuthor(`React with ⛔ if your issue has been resolved.`)
    .setColor('#468DFF')
    .setFooter(`AftNetwork`)

let reactionMessage = null;
try {
  reactionMessage = await channel.send(`${message.author}`, {
embed: embed,
}).then(message => message.channel.send(embed2));
} catch (error) {
  console.log(error);
  return message.channel.send(
    '⚠️ Error sending message in ticket channel!',
  );
}

try {
  await reactionMessage.react('🔒');
  await reactionMessage.react('⛔');
} catch (err) {
  console.log(err);
  return channel.send('⚠️ Error sending emojis!');
}

const collector = reactionMessage.createReactionCollector(
  (reaction, user) => {
    // collect only reactions from the original
    // author and users w/ admin permissions
    const isOriginalAuthor = message.author.id === user.id;
    const isAdmin = message.guild.members.cache
      .find((member) => member.id === user.id)
      .hasPermission('MANAGE_MESSAGES');

    return isOriginalAuthor || isAdmin;
  },
  { dispose: true },
);

collector.on('collect', (reaction, user) => {
  switch (reaction.emoji.name) {
    // lock: admins only
    case '🔒':
      const isAdmin = message.guild.members.cache
        .find((member) => member.id === user.id)
        .hasPermission('MANAGE_MESSAGES');

      if (isAdmin) {
        channel.updateOverwrite(message.author, {
          SEND_MESSAGES: false,
        });
      } else {
        // if not an admin, just remove the reaction
        // like nothing's happened
        reaction.users.remove(user);
      }
      break;
    // close: anyone i.e. any admin and the member
    // created the ticket
    case '⛔':
      channel.send('Deleting this ticket in 5 seconds...');
      setTimeout(() => channel.delete(), 5000);
      break;
  }
});

Have a good day!

Upvotes: 0

Views: 4867

Answers (1)

Moussa Bistami
Moussa Bistami

Reputation: 1087

For now there is no official wrapper so here is an unofficial library that you can use and also here is a small exemple. You can join their discord on the link provided for more help.

let button = new MessageButton()
.setLabel("I like")
.setStyle("blurple")
.setEmoji("🍕")
.setID("like_button")

what you will add is the above code and in the .send() funtion it will be this channel.send(`${message.author}`, {embed: embed, component: button}) and that's basically it.

Upvotes: 1

Related Questions