我正在编程一个不协调的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'
}
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(原始)
答案 0 :(得分:1)
尝试像这样更改它:
if (args[0] === 'off') christian[message.guild.id] = false
else if (args[0] === 'on') christian[message.guild.id] = true
和
return christian