gpt4 book ai didi

javascript - 为什么我的不和谐机器人无法正常上线?

转载 作者:太空宇宙 更新时间:2023-11-04 01:27:37 25 4
gpt4 key购买 nike

所以基本上,我已经尝试了几个小时来解决这个问题,但没有成功。这是我尝试启动机器人时发生的情况:

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);
}
})



包.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)

最佳答案

根据您提供的代码,您的花括号似乎有点问题。 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);

关于javascript - 为什么我的不和谐机器人无法正常上线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56960476/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com