我正在建立一个不和谐的机器人与一个命令处理程序和一些模因命令。我的问题是,当我激活‘基督教模式’或‘无诅咒模式’时,它会在机器人所在的每一个服务器上激活。我的基督教模式代码在这里,横跨Christian.js和Index.js。
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 ? 'Active' : 'Inactive'}`)
return christian
}
exports.help = {
name: 'christian'
}(部分) index.js
if (christian) {
const messages = {
flib: 'frick',
batch: 'nasty person',
nogger: 'nibba',
nafga: 'smelly person',
poohsy: 'child',
poohsyhole: 'child',
cant: 'threat to society',
bestard: 'threat to society',
dock: 'willy'
}
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')
}
})新代码:
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
}这是我的前缀和命令处理程序,有什么需要修改的吗?
发布于 2020-03-24 11:17:08
您可以将christian设置为object,然后将message.guild.id添加为任何值(true或false)的属性,如下所示
const Discord = require('discord.js')
exports.run = (bot, message, args, christian) => {
if (args[0] === 'off') christian[message.guild.id] = false
else if (args[0] === 'on') christian[message.guild.id] = true
message.channel.send(`Christian Mode ${christian[message.guild.id] ? 'Active' : 'Inactive'}`)
return christian
}
exports.help = {
name: 'christian'
}let christian = {}
if (christian[message.guild.id]) {
const messages = {
flib: 'frick',
batch: 'nasty person',
nogger: 'nibba',
nafga: 'smelly person',
poohsy: 'child',
poohsyhole: 'child',
cant: 'threat to society',
bestard: 'threat to society',
dock: 'willy'
}
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')
}
}https://stackoverflow.com/questions/60829715
复制相似问题