为什么我的不和谐机器人会忽略awaitMessages?

时间:2019-06-22 09:30:44

标签: javascript node.js

我尝试使用等待消息将单词存储在数组中,然后将其发送给不和。这是机器人代码:

const Discord = require('discord.js');
const {prefix, token} = require('./config.json');
const client = new Discord.Client();

client.once("ready", (message) => {  
    console.log("Bot is online!");
    client.user.setActivity("Komnata", {type: "WATCHING"});
})

client.on("message", async message => {
    if (message.content.startsWith(`${prefix}role`)) {
        await message.delete();
        const filter = m => {m.author.id === message.author.id};
        message.reply("Choose embed title (message will expire after 10 seconds").then(r => r.delete(10000));
        message.channel.awaitMessages(filter, {max: 1, time: 10000}).then(collected => {
            var newArray = []
            newArray.push(collected);
            message.channel.send(newArray[0])         

        }).catch(err =>{
            message.reply("Time has expired!").then(r => r.delete(3000));
        })
    }

})
client.login(token);

当我向通道(包含一个单词)发送一条消息时,机器人完全忽略了它,并且在控制台中出现错误:

Bot is online!
(node:3228) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message
    at item.request.gen.end (c:\Users\Adam\Desktop\botd\node_modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:85:15)
    at then (c:\Users\Adam\Desktop\botd\node_modules\snekfetch\src\index.js:215:21)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:3228) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:3228) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

1 个答案:

答案 0 :(得分:0)

解决了:我不得不在滤镜上省略大括号