因此,基本上,我已尝试解决此问题达数小时之久,但没有成功。当我尝试启动漫游器时会发生以下情况:
https://gyazo.com/3a941b4372c88be07c76c5b004327f71
我检查了main是否正确,并且一切都正确,例如json文件和实际代码。
bot.js->
const botconfig = require("./botconfig.json");
const Discord = require("discord.js");
const bot = new Discord.Client({disableEveryone: true});
bot.on("ready", async () => {
console.log(`${bot.user.username} is online!`);
bot.user.setActivity("Tickets", {type: "WATCHING"});
});
bot.on('message', async message => {
if(message.author.bot) return;
if(message.channel.type === "dm") return;
let prefix = botconfig.prefix;
let messageArray = message.content.split(" ");
let cmd = messageArray[0];
let args = messageArray.slice(1);
if(cmd === `${prefix}new`){
let embed = new Discord.RichEmbed()
.setTitle("Ticket created")
.setDescription("Ticket #ticket- has been created successfully.")
.setColor("#15f153")
.setFooter("chefren#9582 | 2019")
return message.channel.send(embed);
}
if(cmd === `${prefix}ticketcreation`){
let embed = new Discord.RichEmbed()
.setTitle("Ticket")
.setDescription("Do you require help or support? React with :white_check_mark: ")
.setColor("#15f153")
.setFooter("dl121#9582 | 2019")
msg = await message.channel.send(embed);
await msg.react('✅')
message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
.then(collected => {
const reaction = collected.first();
if (reaction.emoji.name === '✅') {
message.reply('you reacted with a thumbs up.');
}
});
bot.login(botconfig.token);
}
})
Package.json
{
"name": "bot",
"version": "1.0.0",
"description": "A bot",
"main": "bot.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "andrew",
"license": "ISC",
"dependencies": {
"cjs": "0.0.11",
"discord.js": "^11.5.1",
"fs": "0.0.1-security",
"node.js": "0.0.0"
},
"devDependencies": {}
}
在我修复之前有此错误消息:
Error: Cannot find module 'C:\Users\Andrew\Desktop\Discord Bots\Bot\bot,js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
答案 0 :(得分:0)
根据您提供的代码,花括号似乎有点问题。 bot.login({...})
调用实际上是在bot.on('message'
处理程序中。显然,如果不先登录就不会收到消息,所以可能就是这样。
我重新缩进了您的代码,并添加了必要的花括号和括号,以使bot.login
调用在脚本末尾(在任何处理程序函数之外)运行。
const botconfig = require("./botconfig.json");
const Discord = require("discord.js");
const bot = new Discord.Client({disableEveryone: true});
bot.on("ready", async () => {
console.log(`${bot.user.username} is online!`);
bot.user.setActivity("Tickets", {type: "WATCHING"});
});
bot.on('message', async message => {
if(message.author.bot) return;
if(message.channel.type === "dm") return;
let prefix = botconfig.prefix;
let messageArray = message.content.split(" ");
let cmd = messageArray[0];
let args = messageArray.slice(1);
if (cmd === `${prefix}new`) {
let embed = new Discord.RichEmbed()
.setTitle("Ticket created")
.setDescription("Ticket #ticket- has been created successfully.")
.setColor("#15f153")
.setFooter("chefren#9582 | 2019")
return message.channel.send(embed);
}
if (cmd === `${prefix}ticketcreation`) {
let embed = new Discord.RichEmbed()
.setTitle("Ticket")
.setDescription("Do you require help or support? React with :white_check_mark: ")
.setColor("#15f153")
.setFooter("dl121#9582 | 2019")
let msg = await message.channel.send(embed);
await msg.react('✅')
message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })'
.then(collected => {
const reaction = collected.first();
if (reaction.emoji.name === '✅') {
message.reply('you reacted with a thumbs up.');
}
});
}
});
// *** CHANGES WERE MADE ABOVE HERE ***
bot.login(botconfig.token);