簡體   English   中英

無法獲得用戶的邀請總數

[英]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 之后運行這個命令

這是您想要完成的工作實現,有幾點說明:

  1. 創建了一個名為邀請的 Slash 命令來演示此功能。
  2. 如果您想自己嘗試該命令,可以在此處加入演示服務器
  3. 請參閱附加的工作斜杠命令的屏幕截圖
  4. 如果您運行該示例,您將獲得所有創建的邀請
  5. 如果要按用戶id過濾,需要執行Discord中的斜杠命令
響應斜杠命令 在 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM