用于切换功能和启用/禁用的变量 [英] Variable for toggle function and enabling/disabling

查看:57
本文介绍了用于切换功能和启用/禁用的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像我在上一个问题中一样,现在我正在创建一个拖钓功能,我试图弄清楚如何使其切换以使其起作用,这样我的朋友就不必时不时禁止它了。

As in my previous question I was making a troll function now I'm trying to figure out how to make it toggle to make it work so my friend doesn't have to ban it every now and then.

切换命令有效,但实际上在内部不起作用。

The toggle command works but its not actually internally working.

注意:我有两个不一致的帐户,所以我可以在另一个上进行测试。

NOTE: I have two discord accounts so I could test it on the other one.

使用切换的部分在底部

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:");
  };
});

推荐答案

toggle命令实际上有效,尝试将变量打印到某个地方。

The toggle command actually works, try printing the variable out somewhere.

实际上可能是问题出在您的代码结构上, if(! command.startsWith(prefix))return; 如果消息不是以前缀开头,则在处理程序开头附近将退出该函数。

这意味着,此代码如果(message.channel.id!= 425328056777834506)返回,则具有...

What might actually be the problem is your code structure, if(!command.startsWith(prefix)) return; near the start of the handler will exit the function if the message does not start with a prefix.
Which means that, this code you have...

  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:");
  };

除非消息以所需的前缀开头,否则将不会执行。

Will not be executed unless the message starts with the required prefix.

您可以尝试改用else状态,这样...

You could try using a else state instead, which makes it...

  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:");
    }
  }

这篇关于用于切换功能和启用/禁用的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆