node.js - 审核日志消息 Discord JS
问题描述
您好 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 v11。如果您想使用 discord.js v12 执行此操作,请使用MessageEmbed
代替RichEmbed
并使用cache
来获取频道集合message.guild.channels.cache
您可以使用 aRichEmbed
创建所需的嵌入,然后将其发送到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)
推荐阅读
- node.js - TypeError:无法读取未定义的属性“simpleResponse”
- language-features - 'inplace operation' 运算符有任何语言版本吗?
- sql-server - 如何执行“分组依据”之类的操作以在一个字段上运行但在查询中包含所有字段
- asp.net-mvc - 从支付网关.Net MVC 5 重定向后,Google Chrome 版本 84.0.4147.125 会话变为空
- react-native - 尝试移动应用程序入口点不起作用(EXPO)
- python - 在 jupyter notebook 中执行代码存在问题
- python - Python3 - 将数组排序为特定顺序
- python - 动态重命名熊猫df
- python - 如何获取网络根级别内的目录列表
- typescript - TypeScript - 你如何推断接口泛型参数