I have a probleme, I don't know why but when I use the command "!button", I have an error, there is my code for check it:
const discord = require('discord.js');
const client = new discord.Client();
const disbut = require('discord-buttons')(client);
client.on("message", async (message) => {
if (message.content == "!button") { // Use this command only once and only on one channel.
let buttons = new disbut.MessageButton()
.setStyle('green') // Button Color
.setLabel('Test') // Button Name
.setID('Button') // Button ID
message.channel.send('Message Text.', { buttons: [buttons] });
}
if (message.content == "!urlbutton") { // Use this command only once and only on one channel.
let buttons2 = new disbut.MessageButton()
.setStyle('url') // Button Url
.setLabel('Discord') // Button Name
.setURL('https://discord.com') // URL for forwarding
.setDisabled()
message.channel.send('Message Text.', { buttons: [buttons2] });
}
});
the error:
let buttons = new disbut.MessageButton()
^
TypeError: Cannot read property 'MessageButton' of undefined
at Client.<anonymous> (C:\Users\Sans\Desktop\discord-button-main\index.js:8:30)
at Client.emit (node:events:394:28)
at MessageCreateAction.handle (C:\Users\Sans\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\Sans\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
what's the probleme ? I don't really know ^^" (there is not all my code)
I would take a look at this guide to learn more about buttons and interactions.
This uses discord.js v13
To fix the immediate problem, it will require recoding, as follows:
How the buttons are interacted with would be under a different listener: