本文介紹了如何使用此 discord.js 代碼檢查提到的用戶邀請(qǐng)?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我正在嘗試制作一個(gè)不和諧的機(jī)器人來幫助我進(jìn)行服務(wù)器邀請(qǐng)管理,比如 InviteManager 機(jī)器人,這真的很糟糕.我想制作自己的機(jī)器人來做到這一點(diǎn).因此,我進(jìn)一步編寫了代碼來獲取命令作者的邀請(qǐng),但我不知道如何讓它獲取并顯示提到的用戶邀請(qǐng).
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!`);
}
)
}
});
推薦答案
試試這個(gè).
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}`);
}
)
}
});
這篇關(guān)于如何使用此 discord.js 代碼檢查提到的用戶邀請(qǐng)?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!