@magicyan/discord 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/dist/functions/channels.js +2 -2
- package/dist/functions/embeds.js +9 -1
- package/dist/index.js +3 -1
- package/package.json +1 -1
- package/types/functions/embeds.d.ts +4 -1
- package/types/functions/utils.d.ts +1 -1
- package/types/index.d.ts +3 -1
package/README.md
CHANGED
|
@@ -92,4 +92,37 @@ new EmbedBuilder({
|
|
|
92
92
|
author: createEmbedAuthor({ user }),
|
|
93
93
|
description: "My embed description"
|
|
94
94
|
})
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Function to find a channel from the guild cache
|
|
98
|
+
```ts
|
|
99
|
+
const { guild } = interaction
|
|
100
|
+
|
|
101
|
+
const channel = findChannel(guild, ChannelType.GuildVoice).byName("Lounge 01") // VoiceChannel | undefined
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Function to find a role from the guild cache
|
|
105
|
+
```ts
|
|
106
|
+
const { guild } = interaction
|
|
107
|
+
|
|
108
|
+
const role = findChannel(guild).byName("Administrator") // Role | undefined
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Function to create embed asset
|
|
112
|
+
If the method used to obtain a url returns null or undefined the function will set undefined in the image property
|
|
113
|
+
```ts
|
|
114
|
+
const embed = new EmbedBuilder({
|
|
115
|
+
image: createEmbedAsset(guild.iconURL()) // { url: guild.iconUrl() } | undefined
|
|
116
|
+
})
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
When passing an attachment to the function, it will return the url with local attachments
|
|
120
|
+
```ts
|
|
121
|
+
const image = new AttachmentBuilder(buffer, { name: "myImage.png" });
|
|
122
|
+
|
|
123
|
+
const embed = new EmbedBuilder({
|
|
124
|
+
image: createEmbedAsset(image) // { url: attachment://myImage.png }
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
channel.send({ embeds: [embed], files: [image]})
|
|
95
128
|
```
|
|
@@ -6,10 +6,10 @@ function findChannel(guild, type) {
|
|
|
6
6
|
const channelType = type || discord_js_1.ChannelType.GuildText;
|
|
7
7
|
return {
|
|
8
8
|
byName(name) {
|
|
9
|
-
return guild.channels.cache.find(
|
|
9
|
+
return guild.channels.cache.find(channel => channel.name === name && channel.type === channelType);
|
|
10
10
|
},
|
|
11
11
|
byId(id) {
|
|
12
|
-
return guild.channels.cache.find(
|
|
12
|
+
return guild.channels.cache.find(channel => channel.id === id && channel.type === channelType);
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
}
|
package/dist/functions/embeds.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createEmbedAuthor = void 0;
|
|
3
|
+
exports.createEmbedAsset = exports.createEmbedAuthor = void 0;
|
|
4
|
+
const discord_js_1 = require("discord.js");
|
|
4
5
|
function createEmbedAuthor(options) {
|
|
5
6
|
const { user, property = "displayName", imageSize: size = 512, iconURL, url, prefix = "", suffix = "" } = options;
|
|
6
7
|
return {
|
|
@@ -9,3 +10,10 @@ function createEmbedAuthor(options) {
|
|
|
9
10
|
};
|
|
10
11
|
}
|
|
11
12
|
exports.createEmbedAuthor = createEmbedAuthor;
|
|
13
|
+
function createEmbedAsset(source, options) {
|
|
14
|
+
if (source instanceof discord_js_1.Attachment || source instanceof discord_js_1.AttachmentBuilder) {
|
|
15
|
+
return { url: `attachment://${source.name}`, ...options };
|
|
16
|
+
}
|
|
17
|
+
return source ? { url: source, ...options } : undefined;
|
|
18
|
+
}
|
|
19
|
+
exports.createEmbedAsset = createEmbedAsset;
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./constants/client"), exports);
|
|
18
|
-
__exportStar(require("./functions/
|
|
18
|
+
__exportStar(require("./functions/channels"), exports);
|
|
19
19
|
__exportStar(require("./functions/embeds"), exports);
|
|
20
|
+
__exportStar(require("./functions/roles"), exports);
|
|
21
|
+
__exportStar(require("./functions/utils"), exports);
|
|
20
22
|
__exportStar(require("@magicyan/core"), exports);
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EmbedAuthorData, ImageURLOptions, User, EmbedAssetData, Attachment, AttachmentBuilder } from "discord.js";
|
|
2
2
|
interface CreateEmbedAuthorOptions {
|
|
3
3
|
user: User;
|
|
4
4
|
property?: "username" | "displayName" | "id" | "globalName";
|
|
@@ -9,4 +9,7 @@ interface CreateEmbedAuthorOptions {
|
|
|
9
9
|
suffix?: string;
|
|
10
10
|
}
|
|
11
11
|
export declare function createEmbedAuthor(options: CreateEmbedAuthorOptions): EmbedAuthorData;
|
|
12
|
+
type EmbedAssetOptions = Omit<EmbedAssetData, "url">;
|
|
13
|
+
type AssetSource = string | null | Attachment | AttachmentBuilder;
|
|
14
|
+
export declare function createEmbedAsset(source?: AssetSource, options?: EmbedAssetOptions): EmbedAssetData | undefined;
|
|
12
15
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AnyComponentBuilder, LinkButtonComponentData, TextInputComponentData } from "discord.js";
|
|
2
|
-
import { ActionRowBuilder,
|
|
2
|
+
import { ActionRowBuilder, ButtonBuilder, TextInputBuilder } from "discord.js";
|
|
3
3
|
export declare function createRow<Component extends AnyComponentBuilder>(...components: Component[]): ActionRowBuilder<Component>;
|
|
4
4
|
export declare function createModalInput(data: Omit<TextInputComponentData, "type">): ActionRowBuilder<TextInputBuilder>;
|
|
5
5
|
type CreateLinkButtonData = Omit<LinkButtonComponentData, "style" | "type">;
|
package/types/index.d.ts
CHANGED