JS Discord buttons error : 'Cannot send empty message'

JS Discord buttons error : 'Cannot send empty message'

你好,我正在制作一个基于 Javascript 的 Discord 机器人,我真的很想实现新的 Discord 按钮功能,问题是,即使使用文档示例,我也再次遇到同样的错误再次:

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

这是代码(我使用 module.exports 每个命令都有单独的文件):

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);
    }
}

您不能单独发送一个按钮。相反,请尝试将按钮添加到上一条消息中,以便它们都在一条消息中发送,如下所示
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)
});

还有,你是不是忘记初始化 DiscordButtons 了?在初始化 discord 机器人时执行此操作

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