本文介紹了如何使用此 discord.js 代碼檢查提到的用戶邀請?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試制作一個不和諧的機器人來幫助我進行服務器邀請管理,比如 InviteManager 機器人,這真的很糟糕.我想制作自己的機器人來做到這一點.因此,我進一步編寫了代碼來獲取命令作者的邀請,但我不知道如何讓它獲取并顯示提到的用戶邀請.
I am trying to make a discord bot that will help me with my server invite management like InviteManager bot which really sucks. I wanna make my own bot to do that. So further I made code to get invites of Command Author but I don't know how to make it fetch and display mentioned user invites also.
提前致謝
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!`);
}
)
}
});
推薦答案
試試這個.
client.on('message', message => {
if(message.content === "-invites"){
var user = null;
user = message.author;
message.guild.fetchInvites()
.then(invites =>
{
//filter through the invites
const userInvites = invites.array().filter(i => i.inviter.id === user.id);
//get the invites using a for loop
var userInviteLinks = "";
for(var i=0; i < userInvites.length; i++) {
var invite = userInvites[i];
userInviteLinks += `
https://discord.gg/${invite['code']}`;
}
//Sends the message
message.reply(`Here are your invites: ${userInviteLinks}`);
}
)
}
});
這篇關于如何使用此 discord.js 代碼檢查提到的用戶邀請?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!