mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
refactor(embed): allow hex strings in setColor() (#7593)
This commit is contained in:
@@ -2,11 +2,27 @@
|
||||
|
||||
const { Embed: BuildersEmbed } = require('@discordjs/builders');
|
||||
const Transformers = require('../util/Transformers');
|
||||
const { Util } = require('../util/Util');
|
||||
|
||||
/**
|
||||
* Represents an embed object
|
||||
*/
|
||||
class Embed extends BuildersEmbed {
|
||||
constructor(data) {
|
||||
super(Transformers.toSnakeCase(data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color of this embed
|
||||
* @param {ColorResolvable} color The color of the embed
|
||||
* @returns {Embed}
|
||||
*/
|
||||
setColor(color) {
|
||||
if (color === null) {
|
||||
return super.setColor(null);
|
||||
}
|
||||
return super.setColor(Util.resolveColor(color));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Embed;
|
||||
|
||||
3
packages/discord.js/typings/index.d.ts
vendored
3
packages/discord.js/typings/index.d.ts
vendored
@@ -542,6 +542,7 @@ export interface EmbedProviderData {
|
||||
|
||||
export class Embed extends BuildersEmbed {
|
||||
public constructor(data?: EmbedData | APIEmbed);
|
||||
public override setColor(color: ColorResolvable | null): this;
|
||||
}
|
||||
|
||||
export interface MappedChannelCategoryTypes {
|
||||
@@ -3779,7 +3780,7 @@ export type ColorResolvable =
|
||||
| 'DarkButNotBlack'
|
||||
| 'NotQuiteBlack'
|
||||
| 'Random'
|
||||
| readonly [number, number, number]
|
||||
| readonly [red: number, green: number, blue: number]
|
||||
| number
|
||||
| HexColorString;
|
||||
|
||||
|
||||
@@ -107,9 +107,9 @@ import {
|
||||
CategoryChannelChildManager,
|
||||
ActionRowData,
|
||||
MessageActionRowComponentData,
|
||||
Embed,
|
||||
} from '.';
|
||||
import { expectAssignable, expectDeprecated, expectNotAssignable, expectNotType, expectType } from 'tsd';
|
||||
import { Embed } from '@discordjs/builders';
|
||||
|
||||
// Test type transformation:
|
||||
declare const serialize: <T>(value: T) => Serialized<T>;
|
||||
@@ -1342,6 +1342,11 @@ new ButtonComponent({
|
||||
style: ButtonStyle.Danger,
|
||||
});
|
||||
|
||||
// @ts-expect-error
|
||||
new Embed().setColor('abc');
|
||||
|
||||
new Embed().setColor('#ffffff');
|
||||
|
||||
expectNotAssignable<ActionRowData<MessageActionRowComponentData>>({
|
||||
type: ComponentType.ActionRow,
|
||||
components: [
|
||||
|
||||
Reference in New Issue
Block a user