[英]NodeJS - How do i make a command that will run after a command?
I wanted to make a command that will run after a command is called Here's my code: 我想制作一个将在命令被调用后运行的命令,这是我的代码:
ownerID = "12042";
if (message.content.startsWith(config.prefix+"afk on")) {
afk = true;
if (afk == true) {
message.channel.send("Turned on AFK mode");
if (message.content.includes(config.ownerID)) {
message.reply(`X is away. Try again later.`);
}
}
}
if (message.content.startsWith(config.prefix+"afk off")) {
afk = false;
if (afk == false) {
message.channel.send("Turned off AFK mode");
}
}
I tried to make an "AFK mode" command here, and if i send afk on
it will reply X is away
whenever someone typed 12042
. 我尝试在此处执行“ AFK模式”命令,如果我
afk on
其afk on
发送afk on
则无论何时有人键入12042
X is away
都会12042
。
Using that code, i get no answer at all, but if i make it 使用该代码,我根本没有任何答案,但是如果我做到了
if (message.content.includes(config.ownerID)) {
message.reply(`X is away. Try again later.`);
}
it will reply without problems, but it will always reply as we all know 它会毫无问题地答复,但众所周知,它将始终答复
There are three types of messages your bot should be looking for: <prefix>afk on
, <prefix>afk off
, and anything including 12042
. 您的机器人应该寻找三种类型的消息:
<prefix>afk on
, <prefix>afk off
以及包括12042
在内的任何12042
。 Your code only deals with <prefix>afk on
and <prefix>afk off
, with 12042
as a special case of the 'on' message. 您的代码仅处理
<prefix>afk on
和<prefix>afk off
,其中12042
是“ on”消息的特殊情况。 (If you try sending <prefix>afk on 12042
, you should see your away message.) Restructure your code to check all three cases. (如果尝试
<prefix>afk on 12042
发送<prefix>afk on 12042
,则应该看到离开消息。)重组代码以检查所有三种情况。 The simplest (but not necessarily best) way would be something like 最简单(但不一定最好)的方法如下
if (message.content.startsWith(config.prefix+"afk on")) {
// turn on afk mode
} else if (message.content.startsWith(config.prefix+"afk off")) {
// turn off afk mode
} else if (message.content.includes(config.ownerID)) {
// send the afk message if afk mode is on
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.