verify button discord.js v14

Viewed 31

I am trying to create a verify button but i cant get it to work, im very new to discord.js so the code is very messy. i am using discord.js v14 btw I want the verify button to give the person who clicks it the @verified role (1009826361248055438) and to send a message afterwards so they see they have been verified.

const {
  EmbedBuilder,
  ApplicationCommandType,
  ActionRowBuilder,
  ButtonBuilder,
  Message,
  Emoji,
  InviteTargetType,
} = require("discord.js");

module.exports = {
  name: "sendverify",
  description: "send the verify",
  cooldown: 3000,
  type: ApplicationCommandType.ChatInput,
  default_member_permissions: "ManageRoles", // permission required
  options: [
    {
      name: "channel",
      description: "the channel to send it to.",
      type: 7,
      required: true,
    },
  ],
  run: async (client, interaction) => {
    /** Get the buttons
     * @param {Boolean} toggle
     * @param {string}[choice = null] choice
     */
    const getButtons = (toggle = false, choice) => {
      const row3 = new ActionRowBuilder().addComponents(
        new ButtonBuilder()
          .setLabel("Verify")
          .setCustomId("verify")
          .setStyle(
            toggle == true && choice == "green" ? "Secondary" : "Success"
          )
          .setDisabled(toggle)
          .setEmoji("1009822176830034010")
      );

      return row3;
    };

    const channel = interaction.options.get("channel").channel;

    const embed1 = new EmbedBuilder()
      .setTitle("Accepting the rules")
      .setDescription(
        "**Please read the rules before clicking the verify button!**"
      )
      .setColor(0x39f077)
      .setFooter({
        text: "By clicking verify you have agreed to the rules, and face the consequences if you don't follow them.",
      });

    return (
      channel.send({ embeds: [embed1], components: [getButtons()] }),
      interaction.reply({ content: "msg sent.", ephemeral: true })
    );
  },
};
0 Answers
Related