How to fetch a message in a channel gotten via guild.channels.get

Phoenix105

I'm working on improvements for my reaction based cart tracker for discord shops (ie in game items etc)

I'm having an issue where after getting a channel by id, i can't use the fetchMessage function on the variable i saved the channel to to get a specific message. i need this to automatically update the cart message ive already sent upon the user reacting to add an item.

heres my current code:

var cartchannel = messageReaction.message.guild.channels.get(curcart.orderchannelid)
var cartmsg = cartchannel.fetchMessage(curcart.cartmsgid) 
Androz2091

channel.fetchMessage() is an asynchronous function. It means you need to use await or .then(). For example with await:

var cartchannel = messageReaction.message.guild.channels.get(curcart.orderchannelid)
var cartmsg = await cartchannel.fetchMessage(curcart.cartmsgid) 
console.log(cartmsg) // Discord.Message object

or with .then():

var cartchannel = messageReaction.message.guild.channels.get(curcart.orderchannelid)
cartchannel.fetchMessage(curcart.cartmsgid).then((cartmsg) => {
    console.log(cartmsg) // Discord.Message object
});

If you use the await way, you need to be in an async function.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to get the number of voice channels in a guild?

How to fetch a message from the entire guild

How to only get UserID from message.guild.members.fetch() in discord.js v12?

message.guild.channels.find is not a function

TypeError: message.guild.channels.cache is not a function

TypeError: message.guild.channels.forEach is not a functionl

Discord.JS: How to get first channel of a guild?

How do I change message.guild.channels.some in order to make it to work in V12?

How do you make a bot send a message to an specific guild in a specific channel without using commands

how can I force the bot to send a message to a specific channel when the user joined the guild?

Trying to get guild from channel id

TypeError: message.guild.channels.find is not a function discord.js

guild.text_channels return just the top channel instead of all channels

How can I fetch a message from a channel? discord.js

How to get guild object using guild ID

How to get the last message of a specific channel discordjs

How do I get the channel a message was sent in?

Cannot fetch or get channel?

How to lock every channel of a guild with a command?

Edit message in a specific channel in a specific guild | Discord.js

discord.py - Can't send message to channel in other guild

DiscordJS Bot - How to get the message immediately before another message in a channel?

How to get ID from guild.fetch in discord.js v12?

Get guild ID from on_message

how to get the php error message in javascript with fetch

Get first message on channel

How do I define the guild I want to use ".channels" on?

How do I delete all channels in a guild discord.js

How do I DM a user with ID gotten via embed footer?