是否可以通过命令设置日志通道?

时间:2019-09-11 05:28:36

标签: discord.js

我正在创建一个新的审核对象,想知道是否有可能创建一个设置日志通道的命令,例如是否将其设置为#logs,并且如果它们禁止成员,则它将消息发送给#日志谢谢!

我尝试过DB和一台支持服务器,但是没人知道如何创建一个。

我已经尝试过:

if (command === "ban") {

    if (!message.member.hasPermission(["BAN_MEMBERS", "ADMINISTRATOR"])) return message.channel.send("Error: Insufficient Permissions")

    if (!message.guild.me.hasPermission(["BAN_MEMBERS", "ADMINISTRATOR"])) return message.channel.send(`Error: I have Insufficient Permissions to ban Members`)

    let member = message.mentions.members.first() || message.guild.members.get(args[0]);
    if (!member) return message.channel.send(`Error: Missing Arguments, define member\nUsage: ${prefix}ban [member] [reason]`)

    if (member.hasPermission("BAN_MEMBERS", "KICK_MEMBERS", "MANAGE_SERVER", "ADMINISTRATOR", "MANAGE_MESSAGES", "MANAGE_ROLES")) return message.channel.send(`Error: That user is a mod/admin, I can't do that.`)


    if (!member.bannable)
      return message.channel.send(`I cannot ban ${member}`)

    let reason = args.slice(1).join(" ");
    if (!reason) return message.channel.send(`Error: Missing Arguments, define reason\nUsage: ${prefix}ban [member] [reason]`)

    let log = db.fetch(`channel_${message.guild.id}`)

    if (log === null) return

    let logged = message.guild.channels.get(log)

    member.ban(reason)

    logged.send(`Banned!`)


    message.channel.send(`${member.user.tag} has been successfully banned`)

  }

我希望它向已登录的频道发送一条消息。

1 个答案:

答案 0 :(得分:0)

因此,首先创建一个文件,例如setlogchannel.js,将通道保存到数据库中,我确定您使用quick.db,因此您只需复制并粘贴该代码即可。

const {discord, MessageEmbed } = require('discord.js');
let db = require('quick.db')
module.exports.run = async (client, message, args) => {
      try {
  message.delete(15000)
  let ads = db.get(`channel_${message.guild.id}`);
  if (!message.member.hasPermission('ADMINISTRATOR')) return message.reply("Nope!").then(m => m.delete(15000));
  if(!args[0]) return message.reply("You should enter a channel");
  if (!ads) {
    db.set(`channel_${message.guild.id}`, args[1])
    return message.reply("Done, the log channel is :", args).then(msg => msg.delete(15000))
  }
     } catch (error) {
      console.error(error);
      let embed = new MessageEmbed()
        .setTitle('Something went wrong!')
        .setColor('RED');
      return message.say(embed).then(msg => msg.delete({ timeout: 15000}));
    }


}
module.exports.help = {
  name: 'setlogchannel',
  aliases: ['slc']
};              

然后在您的index.js上验证它是否存在,然后将其发送到该频道


if (command === "ban") {

    if (!message.member.hasPermission(["BAN_MEMBERS", "ADMINISTRATOR"])) return message.channel.send("Error: Insufficient Permissions")

    if (!message.guild.me.hasPermission(["BAN_MEMBERS", "ADMINISTRATOR"])) return message.channel.send(`Error: I have Insufficient Permissions to ban Members`)

    let member = message.mentions.members.first() || message.guild.members.get(args[0]);
    if (!member) return message.channel.send(`Error: Missing Arguments, define member\nUsage: ${prefix}ban [member] [reason]`)

    if (member.hasPermission("BAN_MEMBERS", "KICK_MEMBERS", "MANAGE_SERVER", "ADMINISTRATOR", "MANAGE_MESSAGES", "MANAGE_ROLES")) return message.channel.send(`Error: That user is a mod/admin, I can't do that.`)

    if (!member.bannable)
      return message.channel.send(`I cannot ban ${member}`)

    let reason = args.slice(1).join(" ");
    if (!reason) return message.channel.send(`Error: Missing Arguments, define reason\nUsage: ${prefix}ban [member] [reason]`)

    let log = db.fetch(`channel_${message.guild.id}`)

    if (log) {
    let logged = message.guild.channels.get(log)
    logged.send(`Banned!`)
    }
    member.ban(reason)
    message.channel.send(`${member.user.tag} has been successfully banned`)

  }