我正在尝试创建一个不和谐的机器人,在 ping 所有者时,会自动禁止 ping 玩家的作者。问题是,它禁止玩家说任何话,我怎么才能让它只在他们 ping 所有者时才禁止?
这是代码。
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = '<@329005206526361610>'
client.once('ready', () => {
console.log("Wary's Defender Bot is up");
});
function getUserFromMention(mention) {
if (!mention) return;
if (mention.startsWith('!')) {
mention = mention.slice(1);
}
if (mention.startsWith('<@329005206526361610') && mention.endsWith('>')) return {
// mention = mention.slice(2, -1),
return: client.users.cache.get(mention)
}
}
client.on('message', _message => {
// if(!_message.content.users.has('@warycoolio')) return;
const user = getUserFromMention(_message.content);
if(user) return;
console.log('found target')
var member = _message.author
var rMember = _message.guild.member(_message.author)
// ban7, 'lol.'
rMember.ban({ days: 7, reason: 'They deserved it'}); {
// Successmessage
console.log('target dead.')
}
});
答案 0 :(得分:0)
您可以快速检查一下这些提及是否包含对服务器所有者的提及,然后禁止该用户。
client.on("message", _message => {
if (_message.mentions.users.first().id === "owner id") {
message.author.ban()
}
})
答案 1 :(得分:0)
您可以通过检查 _message.mentions.users
和 .has()
并传入公会所有者的 ID 来完成此操作。
.has()
而不是检查消息内容,这将自动检查 Message#mentions
集合。Guild#ownerID
动态获取公会所有者的 ID。client.on('message', _message => {
if (_message.mentions.users.has(_message.guild.ownerID)) {
_message.author.ban({ days: 7, reason: 'They deserved it'});
}
});