chore: typing
This commit is contained in:
@@ -957,33 +957,29 @@ class RichPresence extends Activity {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Assets from a RichPresence (Util)
|
* Retrieves external assets from a RichPresence
|
||||||
* @param {Client} client Discord Client
|
* @param {Client} client - The Discord client instance.
|
||||||
* @param {Snowflake} applicationId Application id
|
* @param {Snowflake} applicationId - The application ID associated with the Rich Presence.
|
||||||
* @param {string} image1 URL image 1 (not from Discord)
|
* @param {...string} images - 1 or 2 external image URLs (not hosted by Discord).
|
||||||
* @param {string} image2 URL image 2 (not from Discord)
|
* @returns {Promise<ExternalAssets[]>}
|
||||||
* @returns {ExternalAssets[]}
|
|
||||||
*/
|
*/
|
||||||
static async getExternal(client, applicationId, image1 = '', image2 = '') {
|
static async getExternal(client, applicationId, ...images) {
|
||||||
if (!client || !client.token || !client.api) throw new Error('Client must be set');
|
if (!client || !client.token || !client.api) throw new Error('Client must be set');
|
||||||
// Check if applicationId is discord snowflake (17 , 18, 19 numbers)
|
// Check if applicationId is discord snowflake (17 , 18, 19 numbers)
|
||||||
if (!/^[0-9]{17,19}$/.test(applicationId)) {
|
if (!/^[0-9]{17,19}$/.test(applicationId)) {
|
||||||
throw new Error('Application id must be a Discord Snowflake');
|
throw new Error('Application id must be a Discord Snowflake');
|
||||||
}
|
}
|
||||||
// Check if large_image is a valid url
|
// Check if images are 1 or 2
|
||||||
if (image1 && image1.length > 0 && !URL.canParse(image1)) {
|
if (images.length > 2) {
|
||||||
throw new Error('Image 1 must be a valid url');
|
throw new Error('RichPresence can only have up to 2 external images');
|
||||||
}
|
}
|
||||||
// Check if small_image is a valid url
|
// Check if all images are valid URLs
|
||||||
if (image2 && image2.length > 0 && !URL.canParse(image2)) {
|
if (images.some(image => !URL.canParse(image))) {
|
||||||
throw new Error('Image 2 must be a valid url');
|
throw new Error('Each image must be a valid URL.');
|
||||||
}
|
}
|
||||||
const data_ = [];
|
|
||||||
if (image1) data_.push(image1);
|
|
||||||
if (image2) data_.push(image2);
|
|
||||||
const res = await client.api.applications[applicationId]['external-assets'].post({
|
const res = await client.api.applications[applicationId]['external-assets'].post({
|
||||||
data: {
|
data: {
|
||||||
urls: data_,
|
urls: images,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
7
typings/index.d.ts
vendored
7
typings/index.d.ts
vendored
@@ -209,12 +209,7 @@ export class RichPresence extends Activity {
|
|||||||
public addButton(name: string, url: string): this;
|
public addButton(name: string, url: string): this;
|
||||||
public setJoinSecret(join?: string): this;
|
public setJoinSecret(join?: string): this;
|
||||||
public setPlatform(platform?: ActivityPlatform): this;
|
public setPlatform(platform?: ActivityPlatform): this;
|
||||||
public static getExternal(
|
public static getExternal(client: Client, applicationId: Snowflake, ...images: string[]): Promise<ExternalAssets[]>;
|
||||||
client: Client,
|
|
||||||
applicationId: Snowflake,
|
|
||||||
image1: string,
|
|
||||||
image2: string,
|
|
||||||
): Promise<ExternalAssets[]>;
|
|
||||||
public toJSON(): object;
|
public toJSON(): object;
|
||||||
public toString(): string;
|
public toString(): string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user