Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Emoji): create getURL() function to get more extension of emoji #8493

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
049f84a
Update MessageDelete.js
dager-mohamed Aug 10, 2022
43256db
Update MessageDelete.js
dager-mohamed Aug 10, 2022
80aaa27
Merge branch 'main' into main
dager-mohamed Aug 10, 2022
4b8722d
Merge branch 'main' of https://github.com/dager-mohamed/discord.js
dager-mohamed Aug 11, 2022
37f5252
Merge branch 'discordjs:main' into main
dager-mohamed Aug 12, 2022
2388a85
feat(AddEmoji): support more extentions in `url()`
dager-mohamed Aug 14, 2022
ec1eb4d
Update Emoji.js
dager-mohamed Aug 14, 2022
db47e9e
Merge branch 'discordjs:main' into main
dager-mohamed Aug 14, 2022
ca4d45a
Update MessageDelete.js
dager-mohamed Aug 14, 2022
21b41da
feat(Emoji): support more extentions in `url()`
dager-mohamed Aug 14, 2022
6bcafc0
support ext 2
dager-mohamed Aug 15, 2022
88e92cd
Create emoji.js
dager-mohamed Aug 15, 2022
a06ce58
Update index.d.ts
dager-mohamed Aug 15, 2022
fecbaba
Update index.d.ts
dager-mohamed Aug 15, 2022
6e78184
Update Emoji.js
dager-mohamed Aug 15, 2022
5c7b085
Update emoji.js
dager-mohamed Aug 15, 2022
66a9eea
`getUrl(ext)` function added and `url` is getter
dager-mohamed Aug 15, 2022
18e9b16
Update index.d.ts
dager-mohamed Aug 15, 2022
aa1c4b6
Update emoji.js
dager-mohamed Aug 15, 2022
95ba713
Update Emoji.js
dager-mohamed Aug 15, 2022
81aec73
Update packages/discord.js/src/structures/Emoji.js
dager-mohamed Aug 15, 2022
e1d2169
Update packages/discord.js/typings/index.d.ts
dager-mohamed Aug 15, 2022
2b320ef
Update Emoji.js
dager-mohamed Aug 15, 2022
d0aaca6
Update emoji.js
dager-mohamed Aug 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/discord.js/src/structures/Emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ class Emoji extends Base {
return this.id && this.client.rest.cdn.emoji(this.id, this.animated ? 'gif' : 'png');
}

/**
* @type {?string}
* @param {ImageExtension} ext the extension of emoji
* @returns {string}
*/
getURL(ext) {
return this.id && this.client.rest.cdn.emoji(this.id, ext);
dager-mohamed marked this conversation as resolved.
Show resolved Hide resolved
}
Comment on lines +59 to +66
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the position of this function needs to be below all of the getter methods

Suggested change
/**
* @type {?string}
* @param {ImageExtension} ext the extension of emoji
* @returns {string}
*/
getURL(ext) {
return this.id && this.client.rest.cdn.emoji(this.id, ext);
}
/**
* @param {ImageExtension} ext the extension of emoji
* @returns {?string}
*/
getURL(ext) {
return this.id && this.client.rest.cdn.emoji(this.id, ext);
}

also corrected documentation

Copy link
Contributor

@jaw0r3k jaw0r3k Jul 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* @type {?string}
* @param {ImageExtension} ext the extension of emoji
* @returns {string}
*/
getURL(ext) {
return this.id && this.client.rest.cdn.emoji(this.id, ext);
}
/**
* Returns an emoji url with the specified extension
* @param {ImageExtension} ext The extension of the emoji
* @returns {?string}
*/
getURL(ext) {
return this.id && this.client.rest.cdn.emoji(this.id, ext);
}


/**
* The timestamp the emoji was created at, or null if unicode
* @type {?number}
Expand Down
27 changes: 27 additions & 0 deletions packages/discord.js/test/emoji.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

const { GatewayIntentBits } = require('discord-api-types/v10');
const { token } = require('./auth.js');
const { Client } = require('../src');

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
],
});

client.on('ready', () => {
console.log('ready');
});

client.on('messageCreate', message => {
if (message.content === 'emoji-test') {
message.guild.emojis.fetch('emoji-id').then(m => console.log(m.getURL('jpg')));
}
});

client.login(token);
3 changes: 2 additions & 1 deletion packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
type RestOrArray,
} from '@discordjs/builders';
import { Collection } from '@discordjs/collection';
import { BaseImageURLOptions, ImageURLOptions, RawFile, REST, RESTOptions } from '@discordjs/rest';
import { BaseImageURLOptions, ImageExtension, ImageURLOptions, RawFile, REST, RESTOptions } from '@discordjs/rest';
import {
APIActionRowComponent,
APIApplicationCommand,
Expand Down Expand Up @@ -1070,6 +1070,7 @@ export class Emoji extends Base {
public name: string | null;
public get identifier(): string;
public get url(): string | null;
public getURL(ext: ImageExtension): string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public getURL(ext: ImageExtension): string;
public getURL(ext: ImageExtension): string | null;

as per previous suggestion the method can return null

public toJSON(): unknown;
public toString(): string;
}
Expand Down