javascript - 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;
}
}
});
解决方案
当你使用discord.io
你想做的
bot.sendMessage({
to: channelID,
message: ':ballot_box: **| ' + user.username + ' started a vote!**'
});
我建议你切换到discord.js
由于discord.io
老旧和无人维护
推荐阅读
- python - 熊猫不识别 TZ 感知日期时间
- javascript - vue js数据中的对象方法
- node.js - NodeJS express 自动创建的应用程序绑定到服务器
- angular - 应该如何在模型中定义字段 dateIni
- amazon-web-services - 如何使用 boto3 附加或更新 API 网关资源策略
- css - 根 div 填充 React(样式化组件)
- java - 错误:捕获异常 [错误:不支持的命令 [selectFrame | 索引=1 | ]] 将代码从 Selenium IDE 导出到 Webdriver
- r - 在 ggplot2 的 x 轴上重复年份
- java - Eclipse E4:“IWorkbenchWindow”未注入 ProgressRegion
- javascript - 遍历 objs 数组,检查值是否存在,返回相反的值 / Javascript