diff --git a/src/errors/Messages.js b/src/errors/Messages.js index 0364a48..d6ea731 100644 --- a/src/errors/Messages.js +++ b/src/errors/Messages.js @@ -215,6 +215,8 @@ const Messages = { LOGIN_FAILED_UNKNOWN: 'Login failed', LOGIN_FAILED_2FA: 'Login failed, 2FA code is required', GUILD_IS_LARGE: 'This guild is too large to fetch all members with this method', + + TEAM_MEMBER_FORMAT: 'The member provided is either not real or not of the User class', }; for (const [name, message] of Object.entries(Messages)) register(name, message); diff --git a/src/managers/DeveloperPortalManager.js b/src/managers/DeveloperPortalManager.js index f1a1c83..a907db0 100644 --- a/src/managers/DeveloperPortalManager.js +++ b/src/managers/DeveloperPortalManager.js @@ -46,6 +46,22 @@ class DeveloperPortalManager extends BaseManager { return this; } + /** + * Creates a new Team. + * @param {string} name Name of the team + * @returns {Promise} + */ + async createTeam(name) { + const team = await this.client.api.teams.post({ + data: { + name: name, + }, + }); + + this.teams.set(team.id, new Team(this.client, team)); + return this.teams.get(team.id); + } + /** * Creates a new application. * @param {string} name Name of the application diff --git a/src/structures/Team.js b/src/structures/Team.js index ccb8175..06d154e 100644 --- a/src/structures/Team.js +++ b/src/structures/Team.js @@ -3,6 +3,8 @@ const { Collection } = require('@discordjs/collection'); const Base = require('./Base'); const TeamMember = require('./TeamMember'); +const User = require('./User'); +const { Error } = require('../errors'); const SnowflakeUtil = require('../util/SnowflakeUtil'); /** @@ -98,6 +100,36 @@ class Team extends Base { return this.client.rest.cdn.TeamIcon(this.id, this.icon, { format, size }); } + /** + * Invite a team member to the team + * @param {User} user The user to invite to the team + * @param {string} MFACode The mfa code + * @returns {Promise} + */ + async inviteMember(user, MFACode) { + if (!(user instanceof User)) return new Error('TEAM_MEMBER_FORMAT'); + const payload = { + username: user.username, + discriminator: user.discriminator, + }; + if (MFACode) payload.code = MFACode; + + const member = await this.client.api.teams(this.id).members.post({ + data: payload, + }); + + this.members.set(member.user.id, new TeamMember(this, member)); + return this.members.get(member.user.id); + } + + /** + * Remove a member from the team + * @param {Snowflake} userID The ID of the user you want to remove + */ + async removeMember(userID) { + await this.client.api.teams[this.id].members[userID].delete(); + } + /** * When concatenated with a string, this automatically returns the Team's name instead of the * Team object.