@magicyan/discord 1.0.9 → 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
CHANGED
|
@@ -106,4 +106,23 @@ Function to find a role from the guild cache
|
|
|
106
106
|
const { guild } = interaction
|
|
107
107
|
|
|
108
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]})
|
|
109
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/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">;
|