我正在构建服务器保护功能。我想听公会踢。我知道在听禁令,但找不到踢踢的赛事。踢有赛事吗?如果没有,有没有办法听踢球?
答案 0 :(得分:2)
您可以在discord.js官方Wiki中找到有关踢事件的帮助。 链接:Link
事件为:guildMemberRemove
这是一个来自https://discordjs.guide的示例(您可以点击Link找到该示例):
client.on('guildMemberRemove', async member => {
const fetchedLogs = await member.guild.fetchAuditLogs({
limit: 1,
type: 'MEMBER_KICK',
});
// Since we only have 1 audit log entry in this collection, we can simply grab the first one
const kickLog = fetchedLogs.entries.first();
// Let's perform a sanity check here and make sure we got *something*
if (!kickLog) return console.log(`${member.user.tag} left the guild, most likely of their own will.`);
// We now grab the user object of the person who kicked our member
// Let us also grab the target of this action to double check things
const { executor, target } = kickLog;
// And now we can update our output with a bit more information
// We will also run a check to make sure the log we got was for the same kicked member
if (target.id === member.id) {
console.log(`${member.user.tag} left the guild; kicked by ${executor.tag}?`);
} else {
console.log(`${member.user.tag} left the guild, audit log fetch was inconclusive.`);
}
});
这不是我的代码。我从discordjs.guide复制了此代码。 您需要事件列表吗?
Here,您可以找到列表。 (来源:https://discord.js.org/和https://discordjs.guide)
答案 1 :(得分:2)
您对renato的评论是正确的,对此的快速解决方案是检查审核日志和联接的时间:
if (kickLog.createdAt < member.joinedAt) {
return console.log(`${member.user.tag} left the guild, most likely of their own will.`);
}
完整代码:
client.on('guildMemberRemove', async member => {
const fetchedLogs = await member.guild.fetchAuditLogs({
limit: 1,
type: 'MEMBER_KICK',
});
// Since we only have 1 audit log entry in this collection, we can simply grab the first one
const kickLog = fetchedLogs.entries.first();
// Let's perform a sanity check here and make sure we got *something*
if (!kickLog) return console.log(`${member.user.tag} left the guild, most likely of their own will.`);
// We now grab the user object of the person who kicked our member
// Let us also grab the target of this action to double check things
const { executor, target } = kickLog;
if (kickLog.createdAt < member.joinedAt) {
return console.log(`${member.user.tag} left the guild, most likely of their own will.`);
}
// And now we can update our output with a bit more information
// We will also run a check to make sure the log we got was for the same kicked member
if (target.id === member.id) {
console.log(`${member.user.tag} left the guild; kicked by ${executor.tag}?`);
} else {
console.log(`${member.user.tag} left the guild, audit log fetch was inconclusive.`);
}
});