首页 > 解决方案 > Javascript Discord Bot 在输出中提及作者

问题描述

我想:

我(Veak):!投票

机器人:Veak 开始投票

它是怎样的:

我(Veak):!投票

机器人:未定义开始投票

我使用的代码是 'message.author + 'started a vote'

我确实尝试了 message.author.username 但我收到一条错误消息,说我没有定义用户名。

代码:

bot.on('message', function (user, userID, channelID, message, evt) {

    if (message.substring(0, 1) == '!') {
        var args = message.substring(1).split(' ');
        var cmd = args[0];

        args = args.splice(1);
        switch(cmd) {

            case 'ping':
                bot.sendMessage({
                    to: channelID,
                    message: 'Pong!'
                });
            break;

            case 'voting':
                bot.sendMessage({
                    to: channelID,
                    message: ':ballot_box: **| ' + message.author + ' started a vote!**'
                });
                break;
         }
    }
});

标签: javascriptdiscord.io

解决方案


当你使用discord.io你想做的

bot.sendMessage({
            to: channelID,
            message: ':ballot_box: **| ' + user.username + ' started a vote!**'
        });

我建议你切换到discord.js由于discord.io老旧和无人维护


推荐阅读