正如我之前的问题,我正在制作一个巨魔功能,现在我正在试图弄清楚如何使其切换以使其工作,所以我的朋友不必时不时地禁止它。
toggle命令有效,但实际上并不在内部工作。
注意:我有两个不和谐帐户,所以我可以在另一个帐户上进行测试。
它使用切换的部分位于底部
const Discord = require("discord.js");
const client = new Discord.Client;
var enabled = true
client.on("message", message => {
if(message.author.bot) return;
let messageArray = message.content.split(" ")
let command = messageArray[0]
let args = messageArray.slice(1)
if(!command.startsWith(prefix)) return;
if (command === `${prefix}cleanup`) {
if (message.author.id != 234430480672358400) {
message.delete()
let embed = new Discord.RichEmbed()
.setColor("#e20909")
.setImage("https://cdn.discordapp.com/attachments/358640529376018432/451111825266835476/unknown.png")
.setTitle(`${message.author.tag}, wow ur mom bad for you trying to use this unauthorized >:(`);
message.channel.sendEmbed(embed)
.then(newMessage => newMessage.delete(5000));
return};
message.delete();
message.channel.send("https://cdn.discordapp.com/attachments/330441704073330688/453693702687162369/yeet.png");
};
if (command===`${prefix}toggle_win`) {
if (message.author.id == 234430480672358400) {
if(enabled === true) {
enabled = false
let embed = new Discord.RichEmbed()
.setColor("#18dd50")
.setImage("https://cdn.discordapp.com/attachments/358640529376018432/451109668002070533/Capturedab.PNG")
.setTitle(`${message.author.tag} success, classifier module is disabled until you repeat the command!`);
message.channel.sendEmbed(embed)
}else{
enabled = true
let embed = new Discord.RichEmbed()
.setColor("#18dd50")
.setImage("https://cdn.discordapp.com/attachments/358640529376018432/451109668002070533/Capturedab.PNG")
.setTitle(`${message.author.tag} success, classifier module is enabled until you repeat the command!`);
message.channel.sendEmbed(embed)
}
}else{
let embed = new Discord.RichEmbed()
.setColor("#e20909")
.setImage("https://cdn.discordapp.com/attachments/358640529376018432/451101447405174785/Capture.PNG")
.setTitle(`${message.author.tag}, ur iq is now -666 try again to have -1337`);
message.channel.sendEmbed(embed)
.then(newMessage => newMessage.delete(5000));
}
}
if (message.channel.id != 425328056777834506) return;
if (enabled === true && message.author.id != 234430480672358400 && Math.floor(Math.random() * Math.floor(4))=== 3 && message.attachments.size > 0) {
message.channel.send("Detected carried win, will now initiate\nhttps://cdn.discordapp.com/attachments/330441704073330688/453693702687162369/yeet.png");
} else if (enabled === true && message.content.search("!cleanup")===-1 && message.author.id != 234430480672358400 && message.attachments.size === 0) {
message.channel.send("send me a poto of ur win :thonk:");
};
});
答案 0 :(得分:1)
toggle命令实际上有效,尝试将变量打印到某处。
实际上可能存在的问题是代码结构,如果消息不以前缀开头,则处理程序开头附近的if(!command.startsWith(prefix)) return;
将退出该函数。
这意味着,你有这个代码......
if (message.channel.id != 425328056777834506) return;
if (enabled === true && message.author.id != 234430480672358400 && Math.floor(Math.random() * Math.floor(4))=== 3 && message.attachments.size > 0) {
message.channel.send("Detected carried win, will now initiate\nhttps://cdn.discordapp.com/attachments/330441704073330688/453693702687162369/yeet.png");
} else if (enabled === true && message.content.search("!cleanup")===-1 && message.author.id != 234430480672358400 && message.attachments.size === 0) {
message.channel.send("send me a poto of ur win :thonk:");
};
除非邮件以所需的前缀开头,否则不会执行。
您可以尝试使用其他状态,这样做......
if(!command.startsWith(prefix))
{
//More stuff or...
return;
} else {
if (message.channel.id != 425328056777834506) return;
if (enabled === true && message.author.id != 234430480672358400 && Math.floor(Math.random() * Math.floor(4))=== 3 && message.attachments.size > 0) {
message.channel.send("Detected carried win, will now initiate\nhttps://cdn.discordapp.com/attachments/330441704073330688/453693702687162369/yeet.png");
} else if (enabled === true && message.content.search("!cleanup")===-1 && message.author.id != 234430480672358400 && message.attachments.size === 0) {
message.channel.send("send me a poto of ur win :thonk:");
}
}