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(Widget): support fetching widget image #8589

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
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
12 changes: 11 additions & 1 deletion packages/discord.js/src/structures/Widget.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { Collection } = require('@discordjs/collection');
const { Routes } = require('discord-api-types/v10');
const { APIVersion, GuildWidgetStyle, Routes } = require('discord-api-types/v10');
const Base = require('./Base');
const WidgetMember = require('./WidgetMember');

Expand Down Expand Up @@ -83,6 +83,16 @@ class Widget extends Base {
this._patch(data);
return this;
}

/**
dager-mohamed marked this conversation as resolved.
Show resolved Hide resolved
* Get Guild Widget Image
Copy link
Member

Choose a reason for hiding this comment

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

This is not a great description

* @param {?GuildWidgetStyle} [style=GuildWidgetStyle.Shield] The style for the widget image
dager-mohamed marked this conversation as resolved.
Show resolved Hide resolved
* @returns {string}
*/
getImageURL(style = GuildWidgetStyle.Shield) {
dager-mohamed marked this conversation as resolved.
Show resolved Hide resolved
const data = `https://discord.com/api/v${APIVersion}${Routes.guildWidgetImage(this.id)}?style=${style}`;
Copy link
Member

Choose a reason for hiding this comment

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

This could be returned directly.

Copy link
Member

Choose a reason for hiding this comment

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

This is not resolved

Copy link
Member

@almeidx almeidx Oct 10, 2022

Choose a reason for hiding this comment

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

Still not resolved (original comment: #8589 (comment)) - Also, is there no function for this link in discord-api-types somewhere?

Copy link
Member

Choose a reason for hiding this comment

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

Besides the previous review, this could use RouteBases.api + Routes.guildWidgetImage(this.id) from discord-api-types (need to handle the query string separately)

return data;
}
}

module.exports = Widget;
2 changes: 2 additions & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ import {
APIEmbedProvider,
AuditLogOptionsType,
TextChannelType,
GuildWidgetStyle,
ChannelFlags,
SortOrderType,
} from 'discord-api-types/v10';
Expand Down Expand Up @@ -3053,6 +3054,7 @@ export class Widget extends Base {
private constructor(client: Client<true>, data: RawWidgetData);
private _patch(data: RawWidgetData): void;
public fetch(): Promise<Widget>;
public getImageURL(style?: GuildWidgetStyle): string;
dager-mohamed marked this conversation as resolved.
Show resolved Hide resolved
public id: Snowflake;
public instantInvite?: string;
public channels: Collection<Snowflake, WidgetChannel>;
Expand Down