首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JS不和谐按钮错误:“无法发送空消息”

JS不和谐按钮错误:“无法发送空消息”
EN

Stack Overflow用户
提问于 2021-06-25 10:43:15
回答 1查看 360关注 0票数 1

嗨,我正在制作一个基于Javascript的不和谐机器人,我真的很想实现新的不和谐按钮特性,问题是,即使使用文档示例,我也会得到相同的错误,一次又一次:

代码语言:javascript
复制
(node:6184) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message

下面是代码(我使用module.exports对每个命令使用分隔的文件):

代码语言:javascript
复制
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);
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-25 10:51:37

你不能单独发送一个按钮。相反,尝试将该按钮添加到前一条消息中,以便它们都在一条消息中发送,如下所示

这方面的正式文件在这里

代码语言:javascript
复制
// 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了吗?当你初始化你的不和谐机器人时就这么做。

代码语言:javascript
复制
// Where you initialized your discord bot
const bot = new Discord.Client()
// Add this line
require("discord-button")(bot)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68129678

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档