diff --git a/src/managers/memberRoles.ts b/src/managers/memberRoles.ts index 6beefb0..ee2880a 100644 --- a/src/managers/memberRoles.ts +++ b/src/managers/memberRoles.ts @@ -20,7 +20,7 @@ export class MemberRolesManager extends BaseChildManager< async get (id: string): Promise { const res = await this.parent.get(id) - const mem = await (this.parent as any).guild.members.get(this.member.id) as MemberPayload + const mem = await (this.parent as any).guild.members._get(this.member.id) as MemberPayload if (res !== undefined && mem.roles.includes(res.id) === true) return res else return undefined } @@ -31,7 +31,7 @@ export class MemberRolesManager extends BaseChildManager< async array (): Promise { const arr = (await this.parent.array()) as Role[] - const mem = await (this.parent as any).guild.members.get(this.member.id) as MemberPayload + const mem = await (this.parent as any).guild.members._get(this.member.id) as MemberPayload return arr.filter( (c: any) => mem.roles.includes(c.id) ) as any diff --git a/src/managers/members.ts b/src/managers/members.ts index acf6e2c..45385fa 100644 --- a/src/managers/members.ts +++ b/src/managers/members.ts @@ -18,11 +18,7 @@ export class MembersManager extends BaseManager { const raw = await this._get(key) if (raw === undefined) return const user = new User(this.client, raw.user) - const res = new this.DataType(this.client, raw, user) - for (const roleid of res.roleIDs as string[]) { - const role = await this.guild.roles.get(roleid) - if (role !== undefined) res.roles.push(role) - } + const res = new this.DataType(this.client, raw, user, this.guild) return res } @@ -31,11 +27,7 @@ export class MembersManager extends BaseManager { this.client.rest.get(GUILD_MEMBER(this.guild.id, id)).then(async data => { await this.set(id, data as MemberPayload) const user: User = new User(this.client, data.user) - const res = new Member(this.client, data as MemberPayload, user) - for (const roleid of res.roleIDs as string[]) { - const role = await this.guild.roles.get(roleid) - if (role !== undefined) res.roles.push(role) - } + const res = new Member(this.client, data as MemberPayload, user, this.guild) resolve(res) }).catch(e => reject(e)) }) diff --git a/src/models/commandClient.ts b/src/models/commandClient.ts index c1f8e0e..3de7ced 100644 --- a/src/models/commandClient.ts +++ b/src/models/commandClient.ts @@ -208,7 +208,7 @@ export class CommandClient extends Client implements CommandClientOptions { command.afterExecute(ctx, result) } catch (e) { if (this.texts.ERROR !== undefined) - return this.sendProcessedText( + this.sendProcessedText( msg, this.texts.ERROR, Object.assign(baseReplaces, { error: e.message }) diff --git a/src/structures/member.ts b/src/structures/member.ts index d970221..dc6d03e 100644 --- a/src/structures/member.ts +++ b/src/structures/member.ts @@ -1,28 +1,30 @@ +import { MemberRolesManager } from "../managers/memberRoles.ts" import { Client } from '../models/client.ts' import { MemberPayload } from '../types/guild.ts' import { Base } from './base.ts' -import { Role } from './role.ts' +import { Guild } from "./guild.ts" import { User } from './user.ts' export class Member extends Base { id: string user: User nick?: string - roleIDs: string[] - roles: Role[] = [] + roles: MemberRolesManager joinedAt: string premiumSince?: string deaf: boolean mute: boolean + guild: Guild - constructor (client: Client, data: MemberPayload, user: User) { + constructor (client: Client, data: MemberPayload, user: User, guild: Guild) { super(client) this.id = data.user.id this.user = user // this.user = // cache.get('user', data.user.id) ?? new User(this.client, data.user) this.nick = data.nick - this.roleIDs = data.roles + this.guild = guild + this.roles = new MemberRolesManager(this.client, this.guild.roles, this) this.joinedAt = data.joined_at this.premiumSince = data.premium_since this.deaf = data.deaf @@ -34,7 +36,6 @@ export class Member extends Base { protected readFromData (data: MemberPayload): void { super.readFromData(data.user) this.nick = data.nick ?? this.nick - this.roleIDs = data.roles ?? this.roles.map(r => r.id) this.joinedAt = data.joined_at ?? this.joinedAt this.premiumSince = data.premium_since ?? this.premiumSince this.deaf = data.deaf ?? this.deaf diff --git a/src/test/cmd.ts b/src/test/cmd.ts index 4b27918..f4d7fe0 100644 --- a/src/test/cmd.ts +++ b/src/test/cmd.ts @@ -11,10 +11,9 @@ client.on('debug', console.log) client.on('ready', () => { console.log(`[Login] Logged in as ${client.user?.tag}!`) - client.rest.get('https://discord.com/api/v8/users/123') }) -client.on('messageCreate', msg => console.log(`${msg.author.tag}: ${msg.content}`)) +// client.on('messageCreate', msg => console.log(`${msg.author.tag}: ${msg.content}`)) client.on("commandError", console.error) diff --git a/src/test/cmds/userinfo.ts b/src/test/cmds/userinfo.ts index 9b65e2f..efbb062 100644 --- a/src/test/cmds/userinfo.ts +++ b/src/test/cmds/userinfo.ts @@ -3,14 +3,17 @@ import { Command, Member, CommandContext, Embed } from '../../../mod.ts' export default class UserinfoCommand extends Command { name = "userinfo" guildOnly = true + aliases = [ 'u', 'user' ] - execute(ctx: CommandContext): void { + async execute(ctx: CommandContext): Promise { const member: Member = ctx.message.member as any + const roles = await member.roles.array() const embed = new Embed() .setTitle(`User Info`) .setAuthor({ name: member.user.tag }) .addField("ID", member.id) - .addField("Roles", member.roles.map(r => r.name).join(", ")) + .addField("Roles", roles.map(r => r.name).join(", ")) + .setColor(0xff00ff) ctx.channel.send(embed) } } \ No newline at end of file