问题是,我安装了带有命令和响应的Discord机器人。我想这样做,例如,当我在不和谐频道中使用“!changeport 2222”时,它将更改里面的实际代码,应将其更改为var port = 2222;。如果我使用“!changeport 80”,则应将其更改为var port = 80;内部脚本。
我尝试了几种方法,但是没有运气。我也不是专业的编码员。
var port = 80;
var portscanner = require('portscanner')
var used = false;
//command that is used in discord channel to change the port
client.on("message", (message) => {
var port = message.content.split(" ")[1]
var cooldowntext = ("You need to wait before using that command!")
if (message.content.startsWith("!port")) {
if(used) message.channel.send(cooldowntext);
else{
portscanner.checkPortStatus(port, '127.0.0.1', function(error, status) {
// Status is 'open' if currently in use or 'closed' if available
message.channel.send("Port changed to ");
console.log(status)
update()
used = true;
setTimeout(() => {
used = false;
}, 1000 * 10);
})
}
}
});
//command that is used in discord channel to change the port /end/
它不能像我尝试的那样工作。
答案 0 :(得分:0)
您需要更改第一个变量的值:
var port = 80;
var portscanner = require('portscanner')
var used = false;
//command that is used in discord channel to change the port
client.on("message", (message) => {
var newPort = message.content.split(" ")[1]
var cooldowntext = ("You need to wait before using that command!")
if (message.content.startsWith("!port")) {
if(used) message.channel.send(cooldowntext);
else{
port = newPort;
portscanner.checkPortStatus(port, '127.0.0.1', function(error, status) {
// Status is 'open' if currently in use or 'closed' if available
message.channel.send("Port changed to ");
console.log(status)
update()
used = true;
setTimeout(() => {
used = false;
}, 1000 * 10);
})
}
}
});
//command that is used in discord channel to change the port /end/
我用port
替换了您的第二个newPort
变量,并在运行命令时将第一个port
的值更改为newPort
的值。