Reputation: 25
let messages = await interaction.channel.messages.fetch();
messages.then(async (messages) => {
const output = messages.array().reverse().map(m => `${new Date(m.createdAt).toLocaleString('en-US')} - ${m.author.tag}: ${m.attachments.size > 0 ? m.attachments.first().proxyURL : m.content}`).join('\n');
console.log(output)
})
and when I get this console log my console log this error:
C:\Users\test7\Desktop\ThunderBot\events\bot\slash-interactionCreate.js:195
messages.then(async (messages) => {
^
TypeError: messages.then is not a function
interaction.channel data: https://hastebin.com/uwocabepoq.yaml
Upvotes: 2
Views: 5742
Reputation: 9041
You are already await
ing the messages. This gives the Collection
of messages which does not have the .then
method (.then
exists on Promise
instances, but not unchanged Collection
instances). Either remove await
to get the Promise
instance or run that without the .then
Removing await
let messages = interaction.channel.messages.fetch();
messages.then(async (messages) => {
const output = messages.array().reverse().map(m => `${new Date(m.createdAt).toLocaleString('en-US')} - ${m.author.tag}: ${m.attachments.size > 0 ? m.attachments.first().proxyURL : m.content}`).join('\n');
console.log(output)
})
Removing .then
let messages = await interaction.channel.messages.fetch();
const output = messages.array().reverse().map(m => `${new Date(m.createdAt).toLocaleString('en-US')} - ${m.author.tag}: ${m.attachments.size > 0 ? m.attachments.first().proxyURL : m.content}`).join('\n');
console.log(output)
Upvotes: 2