我正在尝试创建一个不和谐的机器人,该机器人机器人可以帮助我进行服务器邀请管理,例如InviteManager机器人,这真的很糟糕。我想让自己的机器人做到这一点。因此,我进一步编写了代码以获取Command Author的邀请,但我不知道如何获取和显示提到的用户邀请。
预先感谢
client.on('message', message => {
if(message.content === "-invites"){
var user = null;
user = message.author;
message.guild.fetchInvites()
.then
(invites =>
{
const userInvites = invites.array().filter(o => o.inviter.id === user.id);
var userInviteCount = 0;
for(var i=0; i < userInvites.length; i++)
{
var invite = userInvites[i];
userInviteCount += invite['uses'];
}
message.reply(`You have invited ${userInviteCount} user(s) to this server. Keep up the good work!`);
}
)
}
});
答案 0 :(得分:1)
声明用户时可以添加or运算符-Discord.js v12
client.on('message', message => {
if(message.content === "-invites"){
var user = null;
user = message.author || message.mentions.users.first()
message.guild.fetchInvites().then( invites => {
const userInvites = invites.array().filter(o => o.inviter.id === user.id);
var userInviteCount = 0;
for(var i=0; i < userInvites.length; i++) {
var invite = userInvites[i];
userInviteCount += invite['uses'];
}
message.reply(`You have invited ${userInviteCount} user(s) to this server. Keep up the good work!`);
}
)
}
});
答案 1 :(得分:1)
更像这样,因为它将首先执行第一个参数。 也是其成员而不是用户
client.on('message', message => {
if(message.content === "n!invites"){
var user = null;
user = message.mentions.members.first() || message.author
message.guild.fetchInvites()
.then
(invites =>
{
const userInvites = invites.array().filter(o => o.inviter.id === user.id);
var userInviteCount = 0;
for(var i=0; i < userInvites.length; i++)
{
var invite = userInvites[i];
userInviteCount += invite['uses'];
}
message.reply(`You have ${userInviteCount} invites.`);
}
)
}
});