@magicyan/discord 1.0.9 → 1.0.11
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 +19 -0
- package/dist/functions/channels.js +2 -2
- package/dist/functions/embeds.js +26 -1
- package/package.json +1 -1
- package/types/functions/embeds.d.ts +29 -1
- package/types/functions/utils.d.ts +1 -1
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.createEmbed = 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,27 @@ 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;
|
|
20
|
+
function createEmbed(options) {
|
|
21
|
+
const { extend: extendRaw = {}, ...embedRaw } = options;
|
|
22
|
+
const { color: embedColor, modify, ...embedData } = embedRaw;
|
|
23
|
+
const { color: extendColor, ...extendData } = extendRaw;
|
|
24
|
+
const data = { ...extendData, ...embedData };
|
|
25
|
+
const builder = new discord_js_1.EmbedBuilder(data);
|
|
26
|
+
if (extendColor)
|
|
27
|
+
builder.setColor(extendColor);
|
|
28
|
+
if (embedColor)
|
|
29
|
+
builder.setColor(embedColor);
|
|
30
|
+
if (modify?.fields && typeof modify.fields == "function") {
|
|
31
|
+
const fields = modify.fields(builder.data.fields || []);
|
|
32
|
+
builder.setFields(fields);
|
|
33
|
+
}
|
|
34
|
+
return builder;
|
|
35
|
+
}
|
|
36
|
+
exports.createEmbed = createEmbed;
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EmbedAuthorData, EmbedBuilder, ImageURLOptions, User, EmbedAssetData, Attachment, AttachmentBuilder, ColorResolvable, EmbedFooterData } from "discord.js";
|
|
2
2
|
interface CreateEmbedAuthorOptions {
|
|
3
3
|
user: User;
|
|
4
4
|
property?: "username" | "displayName" | "id" | "globalName";
|
|
@@ -9,4 +9,32 @@ 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;
|
|
15
|
+
type EmbedColor = ColorResolvable | (string & {});
|
|
16
|
+
type BaseEmbedField = {
|
|
17
|
+
name: string;
|
|
18
|
+
value: string;
|
|
19
|
+
inline?: boolean;
|
|
20
|
+
};
|
|
21
|
+
type BaseEmbedData = {
|
|
22
|
+
title?: string;
|
|
23
|
+
color?: EmbedColor;
|
|
24
|
+
description?: string;
|
|
25
|
+
url?: string;
|
|
26
|
+
timestamp?: string | number | Date;
|
|
27
|
+
footer?: EmbedFooterData;
|
|
28
|
+
image?: EmbedAssetData;
|
|
29
|
+
thumbnail?: EmbedAssetData;
|
|
30
|
+
author?: EmbedAuthorData;
|
|
31
|
+
fields?: BaseEmbedField[];
|
|
32
|
+
};
|
|
33
|
+
type CreateEmbedOptions = BaseEmbedData & {
|
|
34
|
+
extend?: BaseEmbedData;
|
|
35
|
+
modify?: {
|
|
36
|
+
fields?(fields: BaseEmbedField[]): BaseEmbedField[];
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export declare function createEmbed(options: CreateEmbedOptions): EmbedBuilder;
|
|
12
40
|
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">;
|