'How do I reply button pressed in discord.js
I am making a discord bot with using buttons, and everything runs fine, no errors, but I am stuck at the point when I click on the button, nothing happens. Since, Discord.js made changes in their recent update, I am not able to find a proper solution. Below is the code-
const { MessageActionRow, MessageButton, MessageEmbed } = require("discord.js")
module.exports ={
name:'ping',
execute(message, arg){
const row = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('id1')
.setLabel('LoL')
.setStyle('DANGER')
)
const ping = new MessageEmbed()
.setDescription('First Button event!')
.setTimestamp()
.setImage('https://images2.alphacoders.com/927/thumbbig-927608.webp')
.setColor('RANDOM')
const lol = new MessageActionRow()
.addComponents(
new MessageButton()
.setStyle('LINK')
.setLabel('Link to Image!')
.setURL('https://images2.alphacoders.com/927/thumbbig-927608.webp')
)
message.channel.send({content :'Hello! This is my first Button event by using command handeler!! ',embeds:[ping], components :[row , lol]})
}
}
Below is the code of the main file
client.on('message', message => {
if(!message.content.startsWith(PREFIX)|| message.author.bot) return
const arg = message.content.slice(PREFIX.length).split(/ +/)
const command = arg.shift().toLowerCase()
if (command === 'ping'){
client.commands.get('ping').execute(message, arg)
}
})
client.on('clickButton', async (button) =>{
} )
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
