mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 12:33:30 +01:00
feat: Add channel & message URL formatters (#8371)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const { channelLink } = require('@discordjs/builders');
|
||||
const { DiscordSnowflake } = require('@sapphire/snowflake');
|
||||
const { ChannelType, Routes } = require('discord-api-types/v10');
|
||||
const Base = require('./Base');
|
||||
@@ -55,7 +56,7 @@ class BaseChannel extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get url() {
|
||||
return `https://discord.com/channels/${this.isDMBased() ? '@me' : this.guildId}/${this.id}`;
|
||||
return this.isDMBased() ? channelLink(this.id) : channelLink(this.id, this.guildId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const { messageLink } = require('@discordjs/builders');
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const { DiscordSnowflake } = require('@sapphire/snowflake');
|
||||
const {
|
||||
@@ -439,7 +440,7 @@ class Message extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get url() {
|
||||
return `https://discord.com/channels/${this.guildId ?? '@me'}/${this.channelId}/${this.id}`;
|
||||
return this.inGuild() ? messageLink(this.channelId, this.id, this.guildId) : messageLink(this.channelId, this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -132,6 +132,23 @@ const {
|
||||
* @returns {string}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Formats a channel link for a channel.
|
||||
* @method channelLink
|
||||
* @param {Snowflake} channelId The id of the channel
|
||||
* @param {Snowflake} [guildId] The id of the guild
|
||||
* @returns {string}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Formats a message link for a channel.
|
||||
* @method messageLink
|
||||
* @param {Snowflake} channelId The id of the channel
|
||||
* @param {Snowflake} messageId The id of the message
|
||||
* @param {Snowflake} [guildId] The id of the guild
|
||||
* @returns {string}
|
||||
*/
|
||||
|
||||
/**
|
||||
* A message formatting timestamp style, as defined in
|
||||
* [here](https://discord.com/developers/docs/reference#message-formatting-timestamp-styles).
|
||||
|
||||
Reference in New Issue
Block a user