PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, July 11, 2022

[FIXED] Why am I getting an error fetching messages?

 July 11, 2022     discord.js, edit, fetch, message     No comments   

Issue

there is an error calling the script. Can you ask for help?

Below I paste the code and the error.

let chn = client.channels.find(channel => channel.id === '717019301357420554');
let msg = chn.fetchMessage('717369584801546273');
msg.edit(embedit);
TypeError: msg.edit is not a function

Solution

Is this v11?

Regardless fetching something is async, so you need to wait for msg to resolve.

https://discord.js.org/#/docs/main/11.1.0/class/TextChannel?scrollTo=fetchMessage

Here's how you can go about it:

First one is using await which needs to be inside of an async function

let chn = client.channels.find(channel => channel.id === '717019301357420554');
let msg = await chn.fetchMessage('717369584801546273');
msg.edit(embedit);

Second is .then

let chn = client.channels.find(channel => channel.id === '717019301357420554');
chn.fetchMessage('717369584801546273').then(msg => msg.edit(embedit));

If you want to save it in a variable

let chn = client.channels.find(channel => channel.id === '717019301357420554');
let msg;
chn.fetchMessage('717369584801546273').then(m => msg = m);
//note you will have to wait for the promise to resolve to use 
//the variable msg correctly
//any code beyond this isn't guranteed to have access to 

These are some bad variable names btw, you shouldn't use abbreviations like chn rather channel, and embedit => embEdit. But up to you



Answered By - user13429955
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing