如何在1个Discord服务器中而不是在漫游器所在的所有Discord服务器中切换命令?

时间:2020-03-25 18:20:33

标签: javascript node.js discord discord.js

我正在编程一个不协调的bot,它具有一些命令,这些命令由我制作的命令处理程序处理。我将在下面包含代码。我的问题是,如果启用该命令,它将在漫游器所在的每个服务器之间切换。那么,如何实现一个message.guild.id系统,该系统仅在键入该命令的服务器中切换命令? Christian.js-正在从处理程序读取外部文件

const Discord = require('discord.js')

exports.run = (bot, message, args, christian) => {
  if (args[0] === 'off') christian = false
  else if (args[0] === 'on') christian = true
  message.channel.send(`Christian Mode ${christian[message.guild.id] ? 'Active' : 'Inactive'}`)
  return christian[message.guild.id]
}

exports.help = {
  name: 'christian'
}
  • 我曾尝试添加行会,但惨败 (一部分)index.js-主文件
bot.on('message', msg => {
  const {author, channel, content} = msg

  if (author.bot) return

  try {
    if (content.startsWith(prefix)) {
      const args = content.toLowerCase().substring(prefix.length).split(/\s+/g)
      const command = args.shift()

      readdir(join(__dirname, 'commands')).then(files => {
        files.map(file => require(join(__dirname, 'commands', file))).forEach(cmd => {
          if (command === cmd.help.name) {
            const resultchristian = cmd.run(bot, msg, args, christian)
            if (typeof resultchristian !== 'undefined') christian = resultchristian
          }
        })
      })
      return
    }
  } catch (error) {
    console.log('Command loading error has cccured')
  }

  if (christian[msg.guild.id]) {
    const messages = {
      fdck: 'frick',
      biadtch: 'nasty person',
      nadr: 'nibba',
      ndga: 'smelly person',
      padsy: 'child',
      pude: 'child',
      casdnt: 'threat to society',
      bdrd: 'threat to society',
      dsk: 'widly'
    }
    try {
      const message = messages[content.toLowerCase()]
      if (message) msg.delete() & channel.send(message).then((m) => m.delete(10000));
    } catch (error) {
      console.log('An error has occurred - make sure the bot has delete message permissions')
    }
  }
})

由于某种原因,我无法使我的代码与公会一起使用。

先谢谢您

Joe(原始)

1 个答案:

答案 0 :(得分:1)

尝试像这样更改它:

 if (args[0] === 'off') christian[message.guild.id] = false
 else if (args[0] === 'on') christian[message.guild.id] = true

return christian