Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
341 views
in Technique[技术] by (71.8m points)

Discord.js - .then is not defined even though it's in a function?

After about 20 hours of searching for answers, editing the code, and trying new methods. I've given up and decided to ask here.

I'm absolutely sick of this piece of code. What I'm trying to do is: 1. Wait for a message to receive 2 reactions 2. After 2 reactions, post message to a separate channel

EDIT: After some users recommended removing my stupidly placed console.log before my .then this code now proceeds to not wait for a reaction on a message and go through the entire process without posting a message to the specified channel Please bear with me, I'm still learning.

Here's the code:

  client.on('message', msg => {
    const filter = (reaction, user) => reaction.emoji.name === '703033480090484756' && user.id === message.author.id;
    msg.awaitReactions(filter, { max: 1, time: 30000, errors: ['time'] })
    .then(collected => {
    const starboard = new Discord.MessageEmbed()
    .setColor(0xFF0000)
    .setAuthor(`${msg.author.username}`, `${msg.author.avatarURL()}`)
    .setDescription(`${msg.author.content}`)
    
     client.channels.cache.get('714842643766444122').send(starboard)})
    .catch(err => console.log(err), ('Passed! Added to starboard.'));
    console.log('Added to Starboard!');

If you need more details, Please ask.

question from:https://stackoverflow.com/questions/65650069/discord-js-then-is-not-defined-even-though-its-in-a-function

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
client.on('message', async msg => {
    let rMessage = await msg.channel.send("Test Message");
    await rMessage.react('703033480090484756');
    const filter = (reaction, user) => reaction.emoji.name === '703033480090484756' && user.id === msg.author.id;
    rMessage.awaitReactions(filter, { max: 1, time: 30000, errors: ['time'] })
    .then(collected => {
    const starboard = new Discord.MessageEmbed()
    .setColor(0xFF0000)
    .setAuthor(`${msg.author.username}`, `${msg.author.displayAvatarURL()}`)
    //.setDescription(`${msg.author.content}`)
    
     client.channels.cache.get('714842643766444122').send(starboard)})
    .catch(err => console.log(err), ('Passed! Added to starboard.'));
    console.log('Added to Starboard!');

You used .then on your console.log('Woah! Passed the filter...').


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...