mirror of
https://github.com/discordeno/discordeno.git
synced 2026-05-31 07:50:07 +00:00
mem.guildID & mem.guild() & chnl.hasPermission()
This commit is contained in:
@@ -116,6 +116,7 @@ This section will list out all the available methods and functionality in the li
|
||||
- mention
|
||||
- raw
|
||||
```ts
|
||||
- .hasPermission(id, permissions)
|
||||
- .getMessage(id)
|
||||
- .getMessages(options)
|
||||
- .getPins()
|
||||
@@ -222,7 +223,9 @@ This section will list out all the available methods and functionality in the li
|
||||
- premiumSince
|
||||
- tag
|
||||
- mention
|
||||
- guildID
|
||||
```ts
|
||||
- .guild()
|
||||
- .avatarURL(size, format)
|
||||
- .addRole(roleID, reason)
|
||||
- .removeRole(roleID, reason)
|
||||
|
||||
@@ -51,6 +51,23 @@ export function createChannel(data: ChannelCreatePayload) {
|
||||
/** The mention of the channel */
|
||||
mention: `<#${data.id}>`,
|
||||
|
||||
/** Checks if a user id or a role id has permission in this channel */
|
||||
hasPermission: function (id: string, permissions: Permissions[]) {
|
||||
const overwrite = data.permission_overwrites?.find((perm) =>
|
||||
perm.id === id
|
||||
) ||
|
||||
data.permission_overwrites?.find((perm) => perm.id === channel.guildID);
|
||||
if (!overwrite) return false;
|
||||
|
||||
return permissions.every((perm) => {
|
||||
if (overwrite.deny & perm) return false;
|
||||
if (overwrite.allow & perm) return true;
|
||||
if (channel.guildID) {
|
||||
return botHasPermission(channel.guildID, [perm]);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
},
|
||||
/** Fetch a single message from the server. Requires VIEW_CHANNEL and READ_MESSAGE_HISTORY */
|
||||
getMessage: async (id: string) => {
|
||||
if (data.guild_id) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import { Errors } from "../types/errors.ts";
|
||||
import { RequestManager } from "../module/requestManager.ts";
|
||||
import { botID } from "../module/client.ts";
|
||||
import { Guild } from "./guild.ts";
|
||||
import { cache } from "../utils/cache.ts";
|
||||
|
||||
export const createMember = (data: MemberCreatePayload, guild: Guild) => ({
|
||||
...data,
|
||||
@@ -26,7 +27,11 @@ export const createMember = (data: MemberCreatePayload, guild: Guild) => ({
|
||||
tag: `${data.user.username}#${data.user.discriminator}`,
|
||||
/** The user mention with nickname if possible */
|
||||
mention: `<@!${data.user.id}>`,
|
||||
/** The guild id where this member exists */
|
||||
guildID: guild.id,
|
||||
|
||||
/** Gets the guild object from cache for this member. This is a method instead of a prop to preserve memory. */
|
||||
guild: () => cache.guilds.get(guild.id)!,
|
||||
/** The users custom avatar or the default avatar */
|
||||
avatarURL: (size: ImageSize = 128, format?: ImageFormats) =>
|
||||
data.user.avatar
|
||||
|
||||
Reference in New Issue
Block a user