Javascript 如何让bot检测它发送的嵌入,并允许用户在Discord.js中使用特定命令?
我想用我的discord机器人制作一个战斗系统,并且我正在尝试允许任何人在发送正确的嵌入后进行攻击。我现在所拥有的是一个随机发送一个地精的事件。我还有一个命令可以“打孔”地精,但是事件脚本和打孔脚本在两个不同的文件夹中。我希望玩家只有在小妖精出现时才能击打小妖精。我尝试使用以下代码检查标题:Javascript 如何让bot检测它发送的嵌入,并允许用户在Discord.js中使用特定命令?,javascript,node.js,discord,discord.js,Javascript,Node.js,Discord,Discord.js,我想用我的discord机器人制作一个战斗系统,并且我正在尝试允许任何人在发送正确的嵌入后进行攻击。我现在所拥有的是一个随机发送一个地精的事件。我还有一个命令可以“打孔”地精,但是事件脚本和打孔脚本在两个不同的文件夹中。我希望玩家只有在小妖精出现时才能击打小妖精。我尝试使用以下代码检查标题: if (message.embeds[0].title.toLowerCase() === 'goblins') { // } 但它没有工作,因为标题是未定义的。我尝试获取最后一条消息,但得到: Sy
if (message.embeds[0].title.toLowerCase() === 'goblins') {
//
}
但它没有工作,因为标题是未定义的。我尝试获取最后一条消息,但得到:
SyntaxError: Unexpected end of input
以下是我的地精事件代码:
const Discord = require('discord.js');
// it is the x in y/x
const goblinChances = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19];
// const client = new Discord.Client();
// client.embed = embed;
const goblinEmbed = {
color: 0x0099ff,
title: 'Goblin',
description: 'Aggressive. It has a knife. It does not seem too powerful',
image: {
url: 'https://static.wikia.nocookie.net/fantendo/images/1/10/BokoblinBotWSplotchless.png/revision/latest?cb=20180108050759',
},
timestamp: new Date(),
};
module.exports = {
name: 'message',
execute(message) {
//randomizes it
const index = Math.floor(Math.random() * goblinChances.length);
//this is the y in y/x
//let index = 0;
console.log(index);
if("MessageIDS") {
//Should put a while loop like while(goblinHealth < 0) { running randomization and sending the embed }
if(index == 0) {
message.channel.send({ embed: goblinEmbed });
}
}
},
};
提前感谢您的帮助。如果还有其他脚本,我很乐意提供。您是否能够添加有关错误确切发生位置的更多详细信息?堆栈跟踪可能会有所帮助。您很可能在代码中的某个地方遗漏了一个右括号,这是导致
语法错误:输入意外结束的常见原因。
module.exports = function(msg, args)
{
const ID = msg.author.id;
const fs = require("fs")
const goblinHealth = require('../goblinHealth.json')
goblinHealth[ID] -= 2;
fs.writeFileSync('../goblinHealth.json', JSON.stringify(goblinHealth));
//msg.reply(goblinHealth[ID]);
const health = require('../health.json')
health[ID] -= 1;
fs.writeFileSync('../health.json', JSON.stringify(health));
msg.reply(health[ID]);
}