1

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

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

1 回答 1

2

您不能只发送一个按钮。相反,请尝试将按钮添加到上一条消息,以便它们都在一条消息中发送,如下所示
官方文档在这里

// 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?在初始化不和谐机器人时执行此操作

// Where you initialized your discord bot
const bot = new Discord.Client()
// Add this line
require("discord-button")(bot)
于 2021-06-25T10:51:37.353 回答