有没有办法用命令切换事件?

Is there a way to toggle an event with command?

有什么方法可以用命令切换事件吗?
我正在尝试创建一个 welcome/farewell 事件,但我不希望它在默认情况下处于活动状态。

这是我的活动现在的样子:

client.on("guildMemberAdd", (member) => {
  const guild = member.guild;
  let memberTag = member.user.tag;
  guild.channels.sort(function(chan1, chan2) {
    if (chan1.type !== `text`) return 1;
    if (!chan1.permissionsFor(guild.me).has(`SEND_MESSAGES`)) return -1;
    return chan1.position < chan2.position ? -1 : 1;
  }).first().send(memberTag + " just joined <:floshed:533687801741443082>");
});

这里是我评论的一个例子:

One way to do it is to store a variable for a guild in some database which has a value of either true or false. Then you'd grab that variable and check if said guild has the option turned on or off

client.on("guildMemberAdd", (member) => {
  const guild = member.guild;
  let memberTag = member.user.tag;

  // Code here to get the guild from database, this is just a non-working example
  let dbGuild = database.get('Guild', guild.id);

  // Check if the guild has the welcome command disabled
  if (dbGuild.enableWelcomeCmd === false) {
    // Breaks the function, no further message will be send
    return;
  }


  guild.channels.sort(function(chan1,chan2){
      if(chan1.type!==`text`) return 1;
      if(!chan1.permissionsFor(guild.me).has(`SEND_MESSAGES`)) return -1;
      return chan1.position < chan2.position ? -1 : 1;
  }).first().send(memberTag + " just joined <:floshed:533687801741443082>");
});

client.on("message", async message => {
  // Check if the msg has been send by a bot
  if(message.author.bot) return;
  // Check if message has correct prefix
  if(message.content.indexOf(config.prefix) !== 0) return;

  const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
  const command = args.shift().toLowerCase();

  // Code for actually changing the guild variable
  if (command === 'toggleWelcome') {
    // Code here to get the guild from database, this is just a non-working example
    let dbGuild = database.get('Guild', message.guild.id);

    dbGuild.enableWelcomeCmd = !dbGuild.enableWelcomeCmd;

    // Save the new variable for the guild (also a non-working example)
    database.save('Guild', message.guild.id, dbGuild);
  }
});

您必须自己研究数据库等,有各种各样的(免费)选项,它们都有不同的语法。那部分是你要弄清楚的,但我希望这能给你一个大概的想法。