XRHTech
XRHTech

Reputation: 45

JS Discord buttons error : 'Cannot send empty message'

Hi I'm making a Javascript based Discord bot, and I really wanted to implement the new Discord Buttons feature, the problem is, even using the documentation examples, I get the same error, again and again :

(node:6184) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message

Here is the code (I am using module.exports with separated files for each commands) :

const { MessageButton } = require('discord-buttons')

module.exports = {
    name: 'invite',
    descritipion: 'test command',
    async execute(client, message, args) {
        let button = new MessageButton()
            .setStyle('url')
            .setURL('https://npmjs.com/discord-buttons')
            .setLabel('Click me !')

        await message.channel.send('Hey, I am powered by npm discord-buttons : https://npmjs.com/discord-buttons');
        await message.channel.send(button);
    }
}

Upvotes: 1

Views: 490

Answers (1)

zS1L3NT
zS1L3NT

Reputation: 500

You cannot just send a button on its own. Instead, try adding the button to the previous message so they both get sent in one message as shown below
The official documentation for this is here

// Replace these
const { MessageButton } = require('discord-buttons')
await message.channel.send('Hey, I am powered by npm discord-buttons : https://npmjs.com/discord-buttons');
await message.channel.send(button);

// With these
const { MessageButton, MessageActionRow } = require('discord-buttons')
await message.channel.send('Hey, I am powered by npm discord-buttons : https://npmjs.com/discord-buttons', {
    component: new MessageActionRow().addComponent(button)
});

Also, did you forget to initialize DiscordButtons? Do it when you initialize your discord bot

// Where you initialized your discord bot
const bot = new Discord.Client()
// Add this line
require("discord-button")(bot)

Upvotes: 2

Related Questions