[英]Cant get the total amount of invites a user did
我正在嘗試將命令作者的邀請邀請到一台服務器[不是多台服務器只是一台]我嘗試了很多解決方案,但許多解決方案似乎已經過時或錯誤。 這是我想出的
exports.run = async (client, message, args) => {
var user = message.author;
message.guild.invites.fetch()
.then
(invites =>
{
const userInvites = invites.filter(o => o.inviter.id === user.id);
var userInviteCount = 0;
console.log(userInvites['uses']);
for(var i=0; i < userInvites.length; i++)
{
var invite = userInvites[i];
userInviteCount += invite['uses'];
}
message.reply(`You have ${userInviteCount} invites.`);
}
)
}
這是在一個invite.js 文件中,所以當用戶runs.invites 它在exports.run 之后運行這個命令
這是您想要完成的工作實現,有幾點說明:
響應斜杠命令 | 在 Fusebit 中運行 |
---|
// Respond to a Slash command
integration.event.on('/:componentName/webhook/:eventType', async (ctx) => {
const {
data: { application_id, token, member },
} = ctx.req.body;
// Store the user id that triggered the bot command.
const commandTriggeredByUser = member.user.id;
const discordClient = await integration.service.getSdk(ctx, connectorName, ctx.req.body.installIds[0]);
const guildInvites = await discordClient.bot.get(`guilds/${DISCORD_DEMO_GUILD_ID}/invites`);
// Filter the user created invites only
const userCreatedInvites = guildInvites.filter(invite => invite.inviter.id === commandTriggeredByUser);
// Reply to the slash command with the number of created invites
await superagent.post(`https://discord.com/api/v8/webhooks/${application_id}/${token}`).send({
content: `You have created ${userCreatedInvites.length} invites`,
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.