【问题标题】:JS Discord buttons error : 'Cannot send empty message'JS Discord 按钮错误:“无法发送空消息”
【发布时间】:2021-07-17 17:45:40
【问题描述】:

您好,我正在制作一个基于 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);
    }
}

【问题讨论】:

    标签: javascript discord discord.js discord-buttons


    【解决方案1】:

    您不能只发送一个按钮。相反,请尝试将按钮添加到上一条消息,以便它们都在一条消息中发送,如下所示
    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?当你初始化你的不和谐机器人时这样做

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

    【讨论】:

    • 感谢您的回复,但这不起作用。嵌入已发送,但按钮仍未发送。
    • 即使进行了此更改,它也不起作用。我什至尝试重新安装不和谐按钮,但效果不佳。虽然我没有收到更多错误,但它没有发送任何内容
    • 好的让我试试
    • 新错误 'UnhandledPromiseRejectionWarning: ReferenceError: MessageActionRow is not defined' 我想我必须定义它,但我不知道如何定义。
    • discord-buttons导入
    猜你喜欢
    • 2019-08-26
    • 1970-01-01
    • 2019-03-05
    • 1970-01-01
    • 2022-01-23
    • 2021-05-29
    • 2021-03-02
    • 2020-03-20
    • 2021-06-28
    相关资源
    最近更新 更多