我有一个将这个机器人上传到的FileZilla服务器。然后,我使用PuTTy启动机器人。我在PuTTy服务器上还有其他3个bot可以正常工作,但是这个机器人的行为有所不同。我经历了与其他3个相同的过程,但是当我执行pm2启动fee.js时,它显示:
费用│3│叉子│在线│135│0%│4.0 KB
现在135在哪里,其他3个机器人具有0。我不确定这是什么意思,但是我假设这就是问题所在。当我通过将cmd更改为bot文件夹并使用node fee.js来使用cmd测试bot时,它可以立即联机,没有任何问题。好奇为什么PuTTy无法解决问题。
我尝试从FileZilla中删除代码,然后重新上传。我已经停止并多次启动了该漫游器。不确定代码是否与此有关。
const Discord = require("discord.js");
const client = new Discord.Client();
client.on("ready", () => {
console.log("Connected as " + client.user.tag);
client.user.setActivity("+help to get started.")
})
client.on("message", (receivedMessage) => {
if(receivedMessage.author == client.user){
return
}
if(receivedMessage.content.startsWith("+")) {
processCommand(receivedMessage)
}
})
function processCommand(receivedMessage) {
let fullCommand = receivedMessage.content.substr(1) // Remove the leading exclamation mark
let splitCommand = fullCommand.split(" ") // Split the message up in to pieces for each space
let primaryCommand = splitCommand[0] // The first word directly after the exclamation is the command
let arguments = splitCommand.slice(1) // All other words are arguments/parameters/options for the command
console.log("Command received: " + primaryCommand)
console.log("Arguments: " + arguments) // There may not be any arguments
if (primaryCommand == "help") {
helpCommand(arguments, receivedMessage)
} else if (primaryCommand == "fees") {
feesCommand(arguments, receivedMessage)
} else {
receivedMessage.channel.send("I don't understand the command. Try `+help` or `+fees`")
}
}
function helpCommand(arguments, receivedMessage) {
if (arguments == "fees") {
receivedMessage.channel.send("It looks like you might need help with fees. Please use `+fees [List Price]` to calculate your payout.")
} else {
receivedMessage.channel.send("To get started, use `+fees [List Price]`")
}
}
function feesCommand(arguments, receivedMessage) {
if (arguments.length < 1) {
receivedMessage.channel.send("Not enough values to calculate. Try `+fees [List Price]`")
return
}
let percent = .05;
arguments.forEach((value) => {
percent = percent * parseFloat(value)
total = arguments - percent
})
receivedMessage.channel.send("The final payout of $" + arguments + " is: $" + total.toString())
}
client.login("token");