我做了一个允许用户设置审核通道的命令。set channel命令可以正常工作并将公会ID和通道ID发送到JSON文件中,如下所示:
{"781631298749726730":{"channel":"781719843770466355"}}
但是在我的unban命令中,我似乎无法使它发送到moderationChannel.json
它只返回以下文件的内部通道:
modChannel.send is not a function
这是unban.js
文件中的代码:
let channels = JSON.parse(fs.readFileSync("././database/moderationChannel.json", "utf8"))
let modChannel = channels[message.guild.id].channel;
if(isNaN(args[0])) return message.channel.send(`${switchc} You need to provide an ID.`)
let bannedMember = await bot.user.fetch(args[0]) || message.guild.members.cache.get(args[0])
if(!bannedMember) return message.channel.send(`${switchc} Please provide a user id to unban someone!`)
let reason = args.slice(1).join(" ")
if(!reason) reason = `${switchc} No reason given!`
if(!message.guild.me.hasPermission(["BAN_MEMBERS", "ADMINISTRATOR"])) return message.channel.send(`${switchc} I dont have permission to perform this command!`)|
message.delete()
try {
message.guild.members.unban(bannedMember, reason)
const bEmbed = new MessageEmbed()
.setColor("RANDOM")
.setDescription(`**${bannedMember.tag}** has been unbanned!`)
message.channel.send(bEmbed)
} catch(e) {
console.log(e.message)
}
let mEmbed = new MessageEmbed()
.setTitle(`Member Unbanned`)
.setDescription("I WORK!")
modChannel.send(mEmbed)
}
}
我使用了我的prefix命令中通道的代码,在其中您为行会设置了前缀。我不知道为什么在某个公会的频道集中发送消息不起作用。
如果您需要在我们设置频道的代码,则下面的代码。
let channels = JSON.parse(fs.readFileSync("././database/moderationChannel.json"));
channels[message.guild.id] = {
channel: message.channel.id
}
fs.writeFile("././database/moderationChannel.json", JSON.stringify(channels), (err) => {
if(err) console.log(err)
});
let sEmbed = new MessageEmbed()
.setColor(aqua)
.setTitle(`${message.guild.name} Channel Set`)
.setDescription(`Set to ${message.channel.name}`);
message.channel.send(sEmbed);
}
}
问题在于,这modChannel
是message.channel.id
一个简单的字符串,即通道的ID,而不是具有send()
方法的通道。
您可以替换let modChannel = channels[message.guild.id].channel
为:
let channelId = channels[message.guild.id].channel;
let modChannel = client.channels.cache.get(channelId);
if (!modChannel) {
return console.log(`No moderation channel found with ID ${channelId}`);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句