admin管理员组

文章数量:1307502

i get this error:

UnhandledPromiseRejectionWarning: TypeError: message.channel.fetchMessages is not a function

on this line

const fetched = await message.channel.fetchMessages({limit: deleteCount});

Anyone know how to fix that? i am not good with the new updates. hehe.

i get this error:

UnhandledPromiseRejectionWarning: TypeError: message.channel.fetchMessages is not a function

on this line

const fetched = await message.channel.fetchMessages({limit: deleteCount});

Anyone know how to fix that? i am not good with the new updates. hehe.

Share Improve this question asked Apr 17, 2020 at 19:52 CrackVibeCrackVibe 211 silver badge2 bronze badges 1
  • If you are using discord.js (please add it in your question's tags, btw) there is no fetchMessages function. – Seblor Commented Apr 17, 2020 at 19:56
Add a ment  | 

4 Answers 4

Reset to default 7

What you are trying to state no longer is in the Discord v12 code. Or it's just redefined as this:

message.channel.messages.fetch

Without seeing the rest of your code it's a bit tricky to be 100% positive, but as the error message says, you're trying to call (Invoke) a nonexisting function fetchMessages. Probably fetchMessages is defined as a property in message.channel and not as a function.

here is rest of the mand code

if(mand === "purge") {

const deleteCount = parseInt(args[0], 10);

if(!deleteCount || deleteCount < 2 || deleteCount > 100)
  return message.reply("Please provide a number between 2 and 100 for the number of messages to delete");

const fetched = await message.channel.fetchMessages({limit: deleteCount});
message.channel.bulkDelete(fetched)
  .catch(error => message.reply(`Couldn't delete messages because of: ${error}`));

}

Changing this:

const fetched = await message.channel.fetchMessages({limit: deleteCount});

to this:

const fetched = await message.channel.messages.fetch({limit: deleteCount});

Should do the trick!

本文标签: