审核日志消息不一致JS

时间:2020-05-05 15:25:00

标签: node.js discord.js

您好,StackOverflow社区,这是我对Discord需要帮助的第一个问题,是否有人可以编辑此代码以使此命令将日志发送到 #logs 通道,并提供以下信息: 1)标题-审核日志 2)用户执行了审核操作 3)采取了哪些缓和措施(在这种情况下为禁令) 4)主持人 5)Footer-Proton Servers Bot©2020


const { client, config, functions } = require('../index.js');

module.exports.run = async (message, u) => {
  if (!message.member.hasPermission('BAN_MEMBERS')) return message.channel.send(functions.errorEmbed('You are not permitted to do this.'));

  if (!u) return message.channel.send(functions.usageEmbed(config.prefix + 'ban <user/id>'));

  const userID = u.match(/[0-9]+/) ? u.match(/([0-9]+)/)[0] : undefined;
  const user = message.guild.members.get(userID);

  if (!user) return message.channel.send(functions.errorEmbed('**' + u + '** is not a valid user.'));

  try {
    await user.ban();
    return message.channel.send(functions.successEmbed('Banned ' + user + ' successfully.'));
  } catch {
    return message.channel.send(functions.errorEmbed('Could not ban ' + user + '. Is their role higher than mine?'));
  }
}

module.exports.description = 'Ban a user.';```

1 个答案:

答案 0 :(得分:0)

此答案适用于discord.js v11。如果要使用discord.js v12进行此操作,请使用MessageEmbed而不是RichEmbed并使用cache获取频道集合message.guild.channels.cache

您可以使用RichEmbed创建所需的嵌入,然后将其发送到log频道。

不过,首先,您必须获得log频道,有两种方法可以做到这一点:

按名称:const logChannel = message.guild.channels.find(channel => channel.name === 'log')

或按ID:const logChannel = message.guild.channels.get(CHANNEL_ID)

然后您可以使用它发送以下嵌入内容

const embed = new Discord.RichEmbed() // Or new RichEmbed depending on how you're importing things
  .setTitle('Moderation Log')
  .addField('Banned', user)
  .addField('Banned By', message.author)
  .setFooter('Proton Servers Bot©2020')

logChannel.send(embed)