Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/421.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 自定义挂起模式(仅适用于开发人员)discordjs_Javascript_Node.js_Discord_Discord.js_Bots - Fatal编程技术网

Javascript 自定义挂起模式(仅适用于开发人员)discordjs

Javascript 自定义挂起模式(仅适用于开发人员)discordjs,javascript,node.js,discord,discord.js,bots,Javascript,Node.js,Discord,Discord.js,Bots,我的朋友在他的discord bot中使用了类似的东西,这是我的代码,无论bot始终处于挂起模式: const { Client, Collection } = require("discord.js"); const { TOKEN, PREFIX, DEV_ID, DEV_PREFIX } = require("./config.json"); client.login(TOKEN); client.suspend = false //other

我的朋友在他的discord bot中使用了类似的东西,这是我的代码,无论bot始终处于挂起模式:

const { Client, Collection } = require("discord.js");
const { TOKEN, PREFIX, DEV_ID, DEV_PREFIX } = require("./config.json");

client.login(TOKEN);
client.suspend = false

//other client.on code

client.on("message", async (message) => {
    if (message.content.startsWith(DEV_PREFIX) && message.author.id == DEV_ID && message.content.includes("suspend")) {
        if (client.suspend = false) {
            client.suspend = true;
            message.channel.send("Suspend mode on!")
        } else if (client.suspend = true) {
            client.suspend = false;
            message.channel.send("Suspend mode off!")
        } else {
            message.channel.send("AHH THERE WAS AN ERROR!!")
            client.suspend = false;
        }
    } 
    if (client.suspend = false) {
    //bot's commands and other functions of the bot that can be turned off during suspend.
    }

预期结果,
//suspend
切换挂起模式,当前结果,bot不侦听命令,挂起模式始终为。

您不签入ifs,您分配:在JavaScript中,您使用
=
进行比较,而
=
用于分配值:您不检查它是否为false,而是将其设置为false。正确的分配如下所示:

const{Client,Collection}=require(“discord.js”);
const{TOKEN,PREFIX,DEV_ID,DEV_PREFIX}=require(“./config.json”);
client.login(令牌);
client.suspend=false
//其他客户端.on代码
client.on(“message”,异步(message)=>{
if(message.content.startsWith(DEV_前缀)&&message.author.id==DEV_id&&message.content.includes(“挂起”)){
如果(!client.suspend){
client.suspend=true;
message.channel.send(“挂起模式打开!”)
}否则{
client.suspend=false;
message.channel.send(“暂停模式关闭!”)
} 
} 
如果(!client.suspend){//缩写==false
//在挂起期间可以关闭的bot命令和bot的其他功能。
}
});

这是因为您没有设置bot所有者或开发人员,因此即使您是bot所有者,也无法运行该命令,因为您设置了该命令,所以除了suspend之外,其他任何命令都无法运行。此外,您还试图检查是否可以使用
=
来分配变量,而不是使用
=
==
进行比较。请尝试在下面签出此代码:


const{Client,Collection}=require(“discord.js”);
const{TOKEN,PREFIX,DEV_ID,DEV_PREFIX}=require(“./config.json”);
client.login(令牌);
client.suspend=false
//其他客户端.on代码
client.on(“message”,异步(message)=>{
if(message.content.startsWith(DEV_前缀)&&message.author.id==DEV_id&&message.content.includes(“挂起”)){
//快速提示:您可以使用'client.suspend'来
//检查它是否为真,`!client.suspend`检查它是否为假。
如果(!client.suspend){
client.suspend=true;
message.channel.send(“挂起模式打开!”)
}else if(client.suspend){
client.suspend=false;
message.channel.send(“暂停模式关闭!”)
}//你再也不需要别的了。
} 
//允许开发人员在挂起状态或挂起状态下运行该命令,以及
//如果命令未挂起,则允许所有用户使用该命令。
if((client.suspend&&message.author.id==DEV_id)| |(!client.suspend)){
//你的命令在这里,所有的…只有开发人员可以使用它,否则,分开
//将您的所有命令转换为可供处于暂停状态的开发人员使用的命令,以及
//可供用户在暂停期间使用的设备。
}
});