【问题标题】:Moderation Log Message Discord JS审核日志消息 Discord JS
【发布时间】:2020-05-05 23:34:42
【问题描述】:

您好 StackOverflow 社区,这是我第一个需要 Discord 帮助的问题,有人可以编辑此代码以使此命令向 #logs 频道发送包含以下信息的日志 1) 标题 - 审核日志 2) 执行审核操作的用户 3) 执行了哪些审核操作(在本例中为禁令) 4) 主持人 5) 页脚 - 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.';```

【问题讨论】:

  • Discord JS 版本:11.5.1 Nodejs 版本:v10.20.0
  • 我的 discord.js 很生锈,尽管我认为可以澄清您的问题以帮助任何试图回答您的问题的人。例如,您在这里有一大段代码;您应该解释其中的某些部分,按预期工作的内容以及所需结果中缺少的内容。

标签: node.js discord.js


【解决方案1】:

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

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

不过,首先,您必须获得log 频道,有两种方法:

按名称:const logChannel = message.guild.channels.find(channel =&gt; 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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-30
    • 2021-10-30
    • 2018-10-27
    • 2019-02-21
    • 1970-01-01
    • 2019-10-02
    • 2018-07-09
    • 2016-03-23
    相关资源
    最近更新 更多