嗨,我正在制作一个基于Javascript的不和谐机器人,我真的很想实现新的不和谐按钮特性,问题是,即使使用文档示例,我也会得到相同的错误,一次又一次:
(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);
}
}发布于 2021-06-25 10:51:37
你不能单独发送一个按钮。相反,尝试将该按钮添加到前一条消息中,以便它们都在一条消息中发送,如下所示
// 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)https://stackoverflow.com/questions/68129678
复制相似问题