Is there a way for my discord bot to notify me when a certain user is playing a particular game?

How can I set up my bot to automatically send a message when a specific user starts playing a specific game, like Left 4 Dead 2? I'm looking for a way to do this without using any commands.

// Game Art Sender //
if (message.channel.id === '573671522116304901') {
  if (msg.includes('!L4D2')) { // THIS is the part that needs to be modified.
    message.channel.send('***[MATURE CONTENT]*** **Joining Game:**', {
      files: [
        "https://cdn.discordapp.com/attachments/573671522116304901/573676850920947733/SPOILER_l4d2.png"
      ]
    });
  }
});

Answer №1

Give this a shot

if(GuildMember.username === 'Different_Username_here')
    if(GuildMember.presence.game === 'Different_Game_here')
        // perform some action here

GuildMember.id could also be utilized if you have the user's specific id string. I haven't personally tested this and would have preferred to leave it as a comment, but unfortunately, I do not have that privilege at the moment.

Answer №2

If you want to send a message to a particular channel, follow these steps:

const specialChannel = message.guild.channels.find(ch => ch.name === 'INPUT_CHANNEL_NAME_HERE')
specialChannel.send("YOUR MESSAGE HERE")

Alternatively, you can use:

const specialChannel = message.guild.channels.find(ch => ch.name === 'INPUT_CHANNEL_NAME_HERE')
specialChannel.send(YOUR_VARIABLE_HERE)

In summary, your code should look something like this:

if(GuildMember.username === 'Enter_Specific_Username_here') {
    if(GuildMember.presence.game === 'Enter_Specific_Game_here') {
        const specialChannel = message.guild.channels.find(ch => ch.name === 'INPUT_CHANNEL_NAME_HERE')
        specialChannel.send("YOUR MESSAGE HERE")
    }
}

Answer №3

After a long journey, I finally cracked the code to this puzzle. Take a look at the solution below:

// Game Detector \\
client.on("presenceUpdate", (oldMember, newMember) => {
if(newMember.id === '406742915352756235') {
    if(newMember.presence.game.name === 'ROBLOX') { // New Example: ROBLOX
        console.log('ROBLOX detected!');
        client.channels.get('573671522116304901').send('**Joining Game:**', {
            files: [
                "https://cdn.discordapp.com/attachments/567519197052272692/579177282283896842/rblx1.png"
                ]
            });
        }
    }
});

But now I'm faced with one more challenge: Every time I close the application, it displays "null."

Can anyone help me fix this issue?

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

When working with Vuejs Composition API, I noticed that the value of a Reference object seems to disappear when I

Here is the code snippet that I am working with: <template> {{posts}} </template> <script> import { computed, ref } from 'vue'; import getPosts from '../composables/getPosts.js' import {useRoute} from 'vue-router ...

What could be the reason for the Nextjs fetch request returning undefined data?

Here is the code snippet for my GET request in the API section: export default async (req, res) => { const { query: { className }, method } = req; switch (method) { case "GET": try { const classDetail = await Class.findO ...

Basic javascript doesn't trigger

Attempting to create a basic AJAX script for testing PHP functionality. However, experiencing issues as the expected output "here" is not appearing due to an error message regarding event.returnValue being deprecated in Chrome. Any insights on what may be ...

Looking to send a user elsewhere if there are no errors present in the javascript errors tag

Looking for a way to redirect users to another page if the #errors are empty. Any advice on how to achieve this successfully? I attempted using an if statement but it didn't work out as expected. $(document).ready(function(){ $( ...

JAVASCRIPT ENCOUNTERS ISSUE WITH RANDOM TEXT GENERATION

Utilizing an array of words, we are in the process of generating random text. The goal is to shuffle and combine these words to form new "random sentences". However, we have encountered a minor issue - the addition of "undefined" at the beginning of each p ...

Send certain attributes from the main component to the subcomponent

When dealing with components, I often find myself needing to manipulate specific children based on their type. For example, in the code snippet below, I want to set additional props on a child component if it matches a certain type: import React from &apo ...

Identifying the FireOS version using JavaScript

Can JavaScript be used to determine the version of FireOS that a Kindle device is running when accessing your website? ...

Managing the scrolling direction horizontally with waypoints.js

As I work on creating a custom wizard form with waypoints, I've encountered an interesting issue that has left me puzzled. In my sample CODEPEN, you can see two pages of the wizard process to better understand the problem. Upon clicking the forward ...

The correct method for implementing server-side rendering with JavaScript

My website consists of multiple pages and utilizes React as a widget toolkit, with different bundles on each page. I am facing an issue where some widget state persists within a login session, and when the user revisits the page, the components should relo ...

There seems to be a glitch in the JavaScript to-do list as it is failing to append new

My attempt at creating a to-do list is not working when I try to add a new entry. Any suggestions? Also, I plan to implement a feature that can calculate the percentage of tasks completed by crossing them off the list. <html> <head> <titl ...

Implementing a basic marker clustering feature in the Google Maps application

I'm currently experiencing issues with implementing marker clusterer functionality on my map. I am trying to use a custom icon for each marker and have individual info windows that are editable. I was able to achieve this, but now I am facing difficu ...

AngularJS checkbox validation requires a minimum of two checkboxes to be selected

When using AngularJS, I am looking to create a validation rule where a minimum of 2 checkboxes must be checked for the input to be considered valid. Here is what I have attempted: <div ng-repeat="item in items"> <label><input type="chec ...

retrieving attribute values from JSON objects using JavaScript

I am struggling to extract certain attribute values from a JSON output and use them as input for a function in JavaScript. I need assistance with this task! Below is the JSON data that I want to work with, specifically aiming to extract the filename valu ...

When the user modifies the input, React fails to update the component state

Currently, I am utilizing React in conjunction with express to server-side render the views for my project. However, I have encountered a minor setback. Within one of my components, users are directed after their initial login. Here, they are prompted to ...

Create an interactive webpage that automatically generates new HTML elements after retrieving JSON data from a Web API during page load

I am currently in the process of developing a hybrid Android App using Phonegap/Apache Cordova. The main function of my app is to retrieve data from my web API, which is being served through JSON. I have implemented the following code snippet for this task ...

Tips for streamlining JavaScript for repetitive event listeners on buttons?

As a beginner in coding, I have been diving into learning about buttons and event handlers. When faced with 50 buttons, I find myself concerned about the potential repetition and clutter in my code. Is there a simpler way to manage all the listed event han ...

The concept of setTimeout and how it affects binding in JavaScript

I have limited experience with jquery, mainly using it for toggling classes. However, I will do my best to explain my issue clearly. I have three div elements and when one is clicked, the other two should rotate 90 degrees and then collapse to a height of ...

Receive information from the server and display it on the front-end

Hello! I'm currently in the process of developing a video uploader for my website. So far, I've successfully been able to upload videos from the front-end (built with React.js) to the back-end public folder (using Node.js) through the POST method ...

Encountered an issue while executing the npm run dev command in a React project

Hello, I am a beginner with React.js and I am currently trying to set up a simple React application locally using webpack. However, when I run the npm run dev command, I encounter the following error: An error occurs in the command prompt after running np ...

Assigning a property to the Next.js response object

I recently discovered a fascinating concept involving setting an attribute on the response object within a Next.js API handler and being able to access that attribute in subsequent requests. This functionality took me by surprise as I couldn't find an ...