Getting messages from a channel

Is there an example anywhere in the guide or docs for fetching messages from a channel? The only examples I can see start with channel.message.fetch() or something along those lines, but Ican't find anything that explains how channel is declared in this context. I assume it is along the lines of const channel = new SomeConstructor(some properties) I'd appreciate any pointers
4 Replies
d.js toolkit
d.js toolkit11mo 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!
xx_lavaboy_xx123
xx_lavaboy_xx12311mo ago
you can also access the channel from various structures for example <Message>.channel
Jon Pitans TA
Jon Pitans TAOP11mo ago
that was really helpful, I was trying to fire it off using a slash command. This is what worked for anyone else in my situation async execute(interaction) { await interaction.reply("last 10 messages are : "); const channel = interaction.client.channels.cache.get( "my channel id as a string" ); await channel.messages .fetch({ limit: 10, cache: false }) .then((messages) => messages.forEach((e, i) => interaction.followUp(e.content)) ); },
Want results from more Discord servers?
Add your server