Answers for "discord.js button"

2

discord.js button

const discord = require('discord.js'); //Define the discord.js module
const client = new discord.Client(); //Creating discord.js client (constructor)
require('discord-buttons')(client);
const { MessageButton, MessageActionRow } = require('discord-buttons')


client.on('message', async message => {
  if(message.content === "test"){
  const button = new MessageButton()
  .setLabel("test")
  .setStyle("green")
  .setID("btn1")

  message.channel.send("test components", button)
  }
})

client.on('clickButton', async (button) => {
  if(button.id === "btn1"){
    await button.reply.defer()
    await button.message.channel.send("button green")
  }
})


client.login('Your Token')
Posted by: Guest on July-22-2021
2

discord.js button

//Note that you need the Node module installed!
let button = new disbut.MessageButton()
  .setStyle('red') //default: blurple
  .setLabel('My First Button!') //default: NO_LABEL_PROVIDED
  .setID('click_to_function') //note: if you use the style "url" you must provide url using .setURL('https://example.com')
  .setDisabled(); //disables the button | default: false

message.channel.send('Hey, i am powered by https://npmjs.com/discord-buttons', button);
Posted by: Guest on May-26-2021
1

discord.js buttons

/*Sending multiple embeds and buttons
Assuming you have them created.
*/

message.channel.send('Optional Normal Text', {
	buttons: [button1, button2],
  	embeds: [embed1, embed2]
})

// You can do the same for sending only 1 button or embed

message.channel.send('option blahblah', {
	button: button1,
  	embed: embed1
})

//Just some alternative ways to do this :)
Posted by: Guest on June-04-2021
0

discord buttons discord.js

npm i discord-buttons
Posted by: Guest on June-18-2021
0

discord.js button

client.on('message', message => {
if(message.content.startsWith(prefix + "ticket-message")) {
    let btn1 = new disbut.MessageButton()
    .setStyle('red')
    .setEmoji(":ticket:")
    .setID('1')
    message.delete()
    message.channel.send(`react here to open a ticket`, btn1)
    }
})
client.on('clickButton', async (button) => {
    await button.defer();
    if(button.id === "1") {
    let btn2 = new disbut.MessageButton()
    .setLabel('close')
    .setStyle('red')
    .setEmoji(":x:")
    .setID('2')
  button.guild.channels.create(`${button.clicker.user.username} ticket`, {
    permissionOverwrites: [
        {
            id: button.guild.roles.everyone,
            deny: ['VIEW_CHANNEL'],
        },
        {
            id: button.clicker.user.id,
            allow: ['VIEW_CHANNEL'],
        },
    ],
}).then(channel => {
      channel.send(`**please wait for our support team \n react with the emoji to close the ticket**`, btn2)

  })

    }
        if(button.id === "2") {
    
     button.channel.send("deleting after 5 seconds")
     setTimeout(function() {
     button.channel.delete();
    }, 5000)
    }
})
Posted by: Guest on June-15-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language