UnhandledPromiseRejectionWarning:未处理的承诺拒绝(拒绝ID:2):TypeEr ror:无法读取null的属性'map'

时间:2017-03-28 11:11:17

标签: javascript discord

所以我正在使用discord.js-commando创建一个机器人。一切正常,直到我尝试做一个sendEmbed,然后我得到错误

(node:25390) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeEr
ror: Cannot read property 'map' of null
(node:25390) 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.

我尝试添加.then和.catch,但到目前为止没有运气。可能是因为我不知道如何让Promise工作。 > _>

我使用以下代码来处理我正在研究的机器人似乎正在解决这个问题。

const commando = require("discord.js-commando");
const modulestuff = module

class Test extends commando.Command {
constructor(client) {
    super(client, {
        name: 'test',
        aliases: ['testing'],
        group: 'random',
        memberName: 'test',
        description: 'Testing',
        examples: [ 'test' ]
    });
}

async run(message, args) {
    let promise = new Promise(function(resolve, reject) {
        resolve(1);
    });
    var bot = new commando.Client();
    promise.then(message.channel.sendEmbed({
        color: 3447003,
        author: {
            name: bot.user.username,
            icon_url: bot.user.avatarURL,
        },
        title: 'Testing101',
        url: 'http://discord.gg/smv3NcP',
        description: 'This is a test command to see if the thing works.',
        Fields: [{
            name: 'Fields',
            value: 'Title Test',
        },
        {
            name: 'Masked Links',
            value: 'Let me see if I can embed a link into this. [masked links](https://discord.gg/smv3NcP)',
        },
        {
            name: 'Markdown',
            value: '*Testing* __101__ _101_ **__101__**'
        }
        ],
        timestamp: new Date(),
        footer: {
            icon_url: bot.user.avatarURL,
            text: 'Requested by ' + message.author,
    }})).catch((error) => {
        console.log('Something went wrong!!');
        done();
    }).then(function() {
        promise.then(message.channel.sendEmbed({
        color: 3447003,
        author: {
            name: bot.user.username,
            icon_url: bot.user.avatarURL,
        },
        title: 'Testing101',
        url: 'http://discord.gg/smv3NcP',
        description: 'This is a test command to see if the thing works.',
        Fields: [{
            name: 'Fields',
            value: 'Title Test',
        },
        {
            name: 'Masked Links',
            value: 'Let me see if I can embed a link into this. [masked links](https://discord.gg/smv3NcP)',
        },
        {
            name: 'Markdown',
            value: '*Testing* __101__ _101_ **__101__**'
        }
        ],
        timestamp: new Date(),
        footer: {
            icon_url: bot.user.avatarURL,
            text: 'Requested by ' + message.author,
        }}));      
    })
}};

module.exports = Test; 

非常感谢任何帮助。

0 个答案:

没有答案