Answer the question
In order to leave comments, you need to log in
How to catch a click on a Discord.js button?
It is necessary to make it so that when you click on the button with the id click_to_function_in_row
, the text is sent. So far this has only worked, but nothing is working. At the very least it throws an error.
TypeError: message.channel.createMessageComponentCollector is not a function
.const Discord = require('discord.js');
const client = new Discord.Client();
const MessageEmbed = require('discord.js');
const disbut = require('discord-buttons');
const MessageButton = require('discord-buttons')
const createMessageComponentCollector = require('discord.js')
disbut(client);
exports.run = async (client, message) => {
const button = new disbut.MessageButton()
.setStyle('url')
.setURL(`https://youtube.com/aquamine`)
.setLabel(`Создатель бота`);
const nsfwbtn = new disbut.MessageButton()
.setStyle('red')
.setID('click_to_function_in_row')
.setLabel('NSFW команды')
const row = new disbut.MessageActionRow()
.addComponent(button)
.addComponent(nsfwbtn);
const embed = new Discord.MessageEmbed()
.setColor('#2f3136')
.setTitle('Список команд:')
.addField('Серверные команды', '`ping`, `serverinfo`, `user`, `avatar`, `8ball`')
.addField('Музыкальные команды', '`play`, `pause`, `resume`, `queue`, `clear-queue`, `shuffle`, `np`, `loop`, `volume`, `skip`, `stop`')
.addField('Модерирование', '`say`, `sayembed`, `check`, `checkping`, `clear`')
.setThumbnail(client.user.displayAvatarURL({ dynamic:true }))
await message.channel.send(embed, { component: row });
const collector = message.channel.createMessageComponentCollector()
collector.on('collect', async i => {
if (i.customId === 'click_to_function_in_row') {
await i.update({ content: 'на кнопку нажали', components: [] });
}
});
};
Answer the question
In order to leave comments, you need to log in
the version of discord.js you are using (12.5.3) is now out of date and no longer officially supported.
.createMessageComponentCollector()
was added in version 13.0.0, so you need to upgrade to use it.
to do this, send the following to the terminal:
npm uninstall discord.js
npm install discord.js
node -v
in the terminal. await message.channel.send(embed, { component: row });
- message.channel.send(embed, { component: row });
+ message.channel.send({ embeds: [embed], components: [row] });
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question