Merge pull request #454 from TheDevYellowy/main

feat: add and remove members from a team
This commit is contained in:
Elysia 2022-12-22 18:06:27 +07:00 committed by GitHub
commit 5c2a64c785
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 0 deletions

View File

@ -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);

View File

@ -46,6 +46,22 @@ class DeveloperPortalManager extends BaseManager {
return this;
}
/**
* Creates a new Team.
* @param {string} name Name of the team
* @returns {Promise<Team>}
*/
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

View File

@ -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<TeamMember>}
*/
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.