Respond to a recommendation with a response

I've been working on setting up a bot for my Discord server, and I recently added a "marry" command to it.

Whenever a user makes an offer, a message announcing the proposal pops up with two reaction options. The first reaction signifies yes, while the second indicates no.

My goal is to allow users to respond to the offer by simply clicking on the reactions instead of typing out their response. Is this a difficult task to accomplish?

I followed the guidelines provided in the documentation at , but unfortunately, my bot doesn't seem to be reacting to any clicked reactions. Any assistance would be greatly appreciated.

(`Are you ready to get married?`).then(message => {
      message.react("👍")
      message.react("👎")
    });

const filter = (reaction) => {
      return ['👍', '👎'].includes(reaction.emoji.name) && message.author.id === userToMarry.id;
    };

      message.awaitReactions({ filter, max: 1, time: 60000, errors: ['time'] })
      .then(collected => {
        const reaction = collected.first();
        if (reaction.emoji.name === '👎') {
      return message.channel.send('I think **no**...')}
        if (reaction.emoji.name === '👍') {
      db.set(message.author.id, { user: message.author.id, partner: userToMarry.id });
      db.set(userToMarry.id, { user: userToMarry.id, partner: message.author.id });
    message.channel.send(`${message.author} and ${userToMarry} now married!`)
      .catch(err => {
        message.channel.send(
          `Something went wrong while trying to marry this user. ${err}`
        );
        return console.log(err)});
      }
  })
  .catch(collected => {
        message.reply('You reacted with neither a thumbs up, nor a thumbs down.');
    });

Here is the complete file:

const { Command } = require('discord.js-commando');
const db = require("quick.db");


module.exports = class MarryCommand extends Command {
  constructor(client) {
    super(client, {
      name: 'marry',
      memberName: 'marry',
      group: 'test',
      description: 'Marry the mentioned user',
      guildOnly: true,
      args: [
        {
          key: 'userToMarry',
          prompt: 'Please select the member you wish to marry.',
          type: 'member'
        }
      ]
    });
  }

  run(message, { userToMarry }) {
    const exists = db.get(`${message.author.id}.user`);
    const married = db.get(`${userToMarry.id}.user`);
    if (!userToMarry) {
      return message.channel.send('Please try again with a valid user.')}
    if (exists == message.author.id) {
      return message.channel.send('You are already married!')}
    if (married == userToMarry.id) {
      return message.channel.send('This user is already married!')}
    if (userToMarry.id == message.author.id) {
      return message.channel.send('You cannot marry yourself!');
    }
    if (exists != message.author.id && married != userToMarry.id) {
    message.channel.send(`**Important announcement!**
    
    ${message.author} makes a marriage proposal ${userToMarry}
    
    Are you ready to get married?`).then(message => {
      message.react("👍")
      message.react("👎")
    });
      message.channel.awaitMessages(message => message.author.id == userToMarry.id, {max: 1}).then(collected => {
    if (collected.first().content.toLowerCase() == 'no') {
      return message.channel.send('I think **no**...')}
    if (collected.first().content.toLowerCase() == 'yes') {
      db.set(message.author.id, { user: message.author.id, partner: userToMarry.id });
      db.set(userToMarry.id, { user: userToMarry.id, partner: message.author.id });
    message.channel.send(`${message.author} and ${userToMarry} now married!`)
      .catch(err => {
        message.channel.send(
          `Something went wrong while trying to marry this user. ${err}`
        );
        return console.log(err)});
      }
  });
}}};

Answer №1

Give this a try

.then(response=> {
      response.reaction('👍').then(() => response.reaction('👎'));
    

      response.waitForReactions((emoji, person) => person.id == selectedPerson.id && (emoji.name == '👍' || emoji.name == '👎'),
        { max: 1, time: 60000, errors: ['time'] })
      .then(collectedReactions => {
        const chosenReaction = collectedReactions.first();
        if (chosenReaction.emoji.name === '👎') {
      return reaction.channel.send('I believe the answer is **no**...')}
    if (chosenReaction.emojii.name === '👍') {
      database.save(selection.sender.id, { user: selection.sender.id, spouse: selectedPerson.id });
      database.save(selectedPerson.id, { user: selectedPerson.id, spouse: selection.sender.id });
    reaction.channel.send(`${selection.sender} and ${selectedPerson} are now married!!`)
 
    ...

  });
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can Ember store in Route handle Post requests?

Is there a way to use ember store functionality similar to this.store.findAll('report') for making POST requests with postObj in my route? Also, how should I handle the response received from these requests? Right now, I am sending ajax POST requ ...

Is there a way for me to keep an image stationary on the page while allowing overlaying text to move?

Currently, I am exploring the process of coding a website that mimics the style of this particular webpage: . I am particularly interested in learning how to create a scrolling effect for text within a fixed area, while keeping the accompanying images st ...

Ensuring the presence of Objects/Functions in different browsers using javascript

I am seeking advice on the best practices for testing object existence for cross-browser compatibility. There are numerous methods available for testing whether an object/function/attribute exists. While I could utilize jQuery or another library, my prefe ...

Issue with implementing MUI Style Tag in conjunction with styled-components and Typescript

I have created a custom SelectType component using Styled Components, which looks like this: import Select from '@mui/material/Select'; export const SelectType = styled(Select)` width:100%; border:2px solid #eaeaef; border-radius:8px ...

What is the best way to transfer a content script variable to a background script in a Chrome Extension?

I am looking to transfer a variable named "website_hostname" from the content script to the background script. This variable holds the hostname of the website you are currently visiting. Content Script: var website_hostname = window.location.href; //Cod ...

Dealing with HTTP upgrade within ExpressJS: A guide

ExpressJS has made a change where it no longer inherits from http.Server. When attempting to listen on the upgrade event, the server is responding with a 404 Not Found. This is a snippet of the current code: app.on('upgrade', function(req, soc ...

Obtaining a state hook value within an imported function in React

In order to access a value from the state hook stored in a special function, it is straightforward to do so in a functional component. For example, this can be achieved in App.js like this: import React from 'react'; import { Switch, Route, with ...

Experiencing an inexplicable blurring effect on the modal window

Introduction - I've implemented a feature where multiple modal windows can be opened on top of each other and closed sequentially. Recently, I added a blur effect that makes the background go blurry when a modal window is open. Subsequently opening an ...

What is preventing me from running the npm run dev command? (node.js/express.js/typescript)

I'm having trouble running npm run dev for my project (Node.js / Express.js / Typescript). I've followed the instructions in the links below but I still keep getting errors. PS C:\Users\Yasser\Documents\WorkspaceNodeJS\M ...

React Error: Invalid Element Type with Named Exports

I've been diving into the world of React hooks and functions, working on three different files. First, there's one that establishes a context called SummaryContext. The second file contains a class component that consumes this context named WikiS ...

Fade out the jQuery message after a brief 2-second pause

In my Rails application, I encountered an issue with a flash message that appears after successfully completing an AJAX action. The message displays "Patient Added" but does not include a way to close it without refreshing the page. To address this, I atte ...

The functionality of scope.$observe is unavailable within an AngularJS Directive

Consider the snippet below: appDirectives.directive('drFadeHighlight', ['$animate', '$timeout', function ($animate, $timeout) { return { scope: { isWatchObject: '=' }, restric ...

Find the total number of table rows that exist between two specific rows using jQuery

<table> <tr id="family_1"> <td>Family 1</td> </tr> <tr class="member"> <td>Member 1</td> </tr> <tr class="member"> <td>Member 2</td> </tr> ... <tr ...

What is the best way to transform the pages extracted through the Notion API into slugs?

I'm new to Next.js and Notion API, and I want to create a blog site on my personal website using the Notion API. While I can easily pull the posts, I am facing a challenge in slugifying the endpoint IDs with post titles. When attempting this based on ...

Customize the antd theme in a create-react-app project without the need to eject webpack

Struggling with customizing antd in my react app. I'm hesitant to mess with the webpack config.js file since I'm not well-versed in webpack. My goal is to avoid having a site that looks like a generic antd clone, but all my attempts at customizat ...

What is the method for locating all anchor tags "In General" within the inner HTML of a div using XPath?

This query is related to a discussion on anchor tags in this thread. I am interested in identifying all anchor tags within a string. The scenario provided below is similar to the aforementioned issue, however, I aim to accomplish this using xpath and angu ...

Develop a client-side API utilizing various libraries

After completing the server side of an API that delivers HTML via JSON using REST through CodeIgniter, I am now exploring how to create a client-side API with JavaScript. The goal is to retrieve data from the server through the API, display it in the DOM, ...

passing JSON data using JavaScript or jQuery

I have a JSON snippet that I need to parse using JavaScript or jQuery and convert into variables: name and meetup. Can you help me with this? Below is the JSON code: { "MYID": 1, "module": [ { "name": "Manchester", ...

Prevent multiple instances of Home screen app on iOS with PWA

There seems to be an issue with the PWA app not functioning properly on iOS devices. Unlike Android, where adding an app to your homescreen will prompt a message saying it's already installed, iOS allows users to add the app multiple times which is no ...

Error: The AjaxMethod "Class" is not defined

I have an older asp.net project that utilizes Ajax.AjaxMethod() to invoke server-side code from Javascript. It used to function properly, but now it has suddenly ceased to work. Here is the C# code behind: public partial class Signup : System.Web.UI.Page ...