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 14 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
13 changes: 9 additions & 4 deletions packages/discord.js/src/structures/Emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ class Emoji extends Base {
return encodeURIComponent(this.name);
}

/**
/**
* The URL to the emoji file if it's a custom emoji
* @type {?string}
* @readonly
* @param {ImageExtension} extension the extension of emoji
* @returns {string}
*/
get url() {
return this.id && this.client.rest.cdn.emoji(this.id, this.animated ? 'gif' : 'png');
url(extension) {
let final_result;
const extensions = ['webp', 'png', 'jpg', 'jpeg', 'gif'];
if (!extensions.includes(extension)) extension = this.animated ? 'gif' : 'png';
final_result = this.id && this.client.rest.cdn.emoji(this.id, extension);
return final_result;
dager-mohamed marked this conversation as resolved.
Show resolved Hide resolved
}

/**
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('1008538563236872193').then(m => console.log(m.url()));
}
});

client.login(token);
4 changes: 2 additions & 2 deletions 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 @@ -1069,7 +1069,7 @@ export class Emoji extends Base {
public id: Snowflake | null;
public name: string | null;
public get identifier(): string;
public get url(): string | null;
public url(extension?: ImageExtension): string | null;
public toJSON(): unknown;
public toString(): string;
}
Expand Down