Fetch a message by using the url

I know we can get a message with channel and message ID, but maybe it exists a methods to get from url directly, instead of parsing the URL (like regex) and get channel and after the message ? (It's a general question but in case of : - discord.js : [email protected] - node : v18.18.0 )
5 Replies
d.js toolkit
d.js toolkit8mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Carved
Carved8mo ago
const url = 'https://discord.com/channels/123456789012345678/123456789012345678/123456789012345678';
const url = 'https://discord.com/channels/123456789012345678/123456789012345678/123456789012345678';
https://discord.com/channels/[guildID]/[channelID]/[messageID]
Mara
MaraOP8mo ago
Yeah, but here is a function to get the message from the URL ? For the moment, I use like:
const channel = await interaction.guild?.channels.fetch(managerID);
const message = await thread.messages.fetch(userMessageId);
const channel = await interaction.guild?.channels.fetch(managerID);
const message = await thread.messages.fetch(userMessageId);
I want to know if there is a better "direct" methods (without using cache)
Carved
Carved8mo ago
function parseDiscordUrl(url) {
const urlObject = new URL(url);
const path = urlObject.pathname;
const parts = path.split('/');
return {
guildID: parts[2],
channelID: parts[3],
messageID: parts[4]
};
}
function parseDiscordUrl(url) {
const urlObject = new URL(url);
const path = urlObject.pathname;
const parts = path.split('/');
return {
guildID: parts[2],
channelID: parts[3],
messageID: parts[4]
};
}
should like this !
Mara
MaraOP8mo ago
Well, im always afraid to don't found channel and I spotted sometimes the error "channel not found"
Want results from more Discord servers?
Add your server