Reputation: 45
I am trying to get the invites of the author of the command to the one server [Not multiple servers just one] I have tried many solutions but many seem outdated or wrong. Here is what I came up with
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.`);
} )
}
This is in an invite.js file so when a user runs !invites it runs this command after exports.run
Upvotes: 2
Views: 81
Reputation: 1206
Here is a working implementation from what you want to accomplish, a few notes:
Responding to a slash command | Run in 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`,
});
});
Upvotes: 2