如何使用突击队框架在 discord.js 禁止和踢命令中添加原因?
我目前正在开发一个带有 commando 的 discord.js
机器人(这是 discord.js 创建者的官方框架/命令处理程序)
我在各种网站上研究过这个主题,但我的突击队框架似乎没有任何效果.
这是代码
I'm currently working on a discord.js
bot with commando (which is the official framework/commands handler from the discord.js creator)
I have researched this subject on various websites and nothing seems to work with my commando framework.
This is the code
const Commando = require("discord.js-commando");
module.exports = class banCommands extends (
Commando.Command
) {
constructor(client) {
super(client, {
name: "ban",
aliases: ["bans"],
group: "general",
memberName: "ban",
description: "Banned the mention member from the server",
});
}
run(message) {
const target = message.mentions.users.first();
if (!target) {
message.reply("you need to have at least one users mentioned");
return;
}
const { guild } = message;
const member = guild.members.cache.get(target.id);
if (member.bannable) {
guild.members.ban(member);
message.reply("That user has been banned");
} else {
message.reply("You cannot ban that user.");
console.log(target);
}
}
};
有什么建议吗?或任何具有相同主题的东西?
Any suggestion? or anything that have the same subject?
谢谢
推荐答案
您需要将它放在 options
参数中(参见 docs).您也应该使用 member.ban
而不是 guild.members.ban(member)
,但无论如何,这里有一个例子:
You'll need to put it in the options
argument (see the docs). You should also probably use member.ban
instead of guild.members.ban(member)
, but anyways, here's an example:
member.ban({
reason: "Your reason here"
});
并且该成员将被禁止,审核日志中的推理会正确显示.您还应该在命令中添加 reason
参数.不要问我怎么回事,我已经有一年没有接触过 discord.js 了,尤其是突击队.检查指南.提及第一个论点,然后提及原因.
And the member will be banned, with the reasoning in audit logs showing up properly. You should add an reason
argument to your command as well. Don't ask me how though, I haven't touched discord.js in a year and especially not commando. Check the guide for that. Make the mention the first argument and the reason the rest.
相关文章