"Create a custom JavaScript Discord Bot that includes a feature to mention the

I'm looking for:

ME (Veak): !voting

Bot: Veak initiated a poll

Current situation:

Me (Veak): !voting

Bot: undefined initiated a vote

The previous code I utilized was 'message.author + 'initiated a vote'

When I attempted message.author.username, an error message prompted me that the username is not defined.

The code snippet:

bot.on('message', function (user, userID, channelID, message, evt) {

    if (message.substring(0, 1) == '!') {
        var args = message.substring(1).split(' ');
        var cmd = args[0];

        args = args.splice(1);
        switch(cmd) {

            case 'ping':
                bot.sendMessage({
                    to: channelID,
                    message: 'Pong!'
                });
            break;

            case 'voting':
                bot.sendMessage({
                    to: channelID,
                    message: ':ballot_box: **| ' + message.author + ' initiated a vote!**'
                });
                break;
         }
    }
});

Answer №1

If you are utilizing the discord.io platform, it is advisable to follow these steps:

bot.sendMessage({
            to: channelID,
            message: ':ballot_box: **| ' + user.username + ' initiated a voting process!**'
        });

I suggest transitioning to discord.js as discord.io is outdated and not regularly updated.

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

Is there a way to simulate Pinia and vue-i18n simultaneously?

Exploring Vue 3's Composition API with a twist: The store.ts file import { ref, Ref } from 'vue'; import { defineStore } from 'pinia'; export const useStore = defineStore('store', () => { const isLoading: Ref<bo ...

Putting off the execution of a setTimeout()

I'm encountering difficulties with a piece of asynchronous JavaScript code designed to fetch values from a database using ajax. The objective is to reload a page once a list has been populated. To achieve this, I attempted to embed the following code ...

Tips for resolving the issue of dropdown menus not closing when clicking outside of them

I am currently working on an angular 5 project where the homepage consists of several components. One of the components, navbarComponent, includes a dropdown list feature. I want this dropdown list to automatically close when clicked outside of it. Here i ...

Tips for integrating my Python random forest classifier in a web application built using HTML, Javascript, and Node.js

Greetings! I am currently in the process of creating a machine learning web application that requires the use of a random forest classifier. However, I am unsure of how to properly integrate the python code with it. Any guidance would be greatly apprecia ...

Determining the query count in a MongoDB collection using Node.js

Exploring the world of MongoDb, I have embarked on a project to create a small phonebook application. This application allows users to add and remove entries with a name and phone number. While I have successfully implemented the functionality to add and d ...

Encountering Axios CanceledError while attempting to forward a POST request using Axios

While attempting to relay a POST request from an express backend to another backend using axios, I encountered an axios error stating "CanceledError: Request stream has been aborted". Interestingly, this issue does not arise when dealing with GET requests. ...

Display the contents of a post within the same page using ReactJS

I am currently in the process of setting up a blog. In my index.js file, I have a left sidebar that displays the links to the articles. My goal is to have the post content show up in the right sidebar of the index.js file when I click on a link, instead of ...

Dynamic tooltips with jQuery: enhancing user experience through mouseover and

I seem to have encountered a problem with the functioning of my tooltip. Everything works fine, except when I move my cursor towards the right side, it tends to be faster than the tooltip itself and ends up hovering over it momentarily. This results in the ...

In the process of managing various API requests through a Node/Express middleware API, experimenting with the implementation of promise.all()

As I navigate through this project, I am stumbling upon various gaps in my knowledge. My current task involves constructing an intermediate API server. Some of the endpoints require processing an array of information, initiating external calls for each pie ...

What could be causing the first bar in Chart.js to appear smaller or not show up at all?

Hey there, I'm currently working on displaying some bar charts using Charts js. However, I've run into an issue with the first column not showing up correctly. Here is my code snippet: var options = { scales: { yAxes: [{ display: tru ...

Unable to establish a new pathway in the index.js file of a Node.js and Express website running on Heroku

I recently made some changes to my index.js file: const express = require('express'); const path = require('path'); const generatePassword = require('password-generator'); const fetch = require('node-fetch'); const ...

I am interested in tracking the time elapsed when the browser is active

After recently embarking on the journey of developing my very first Chrome extension, I encountered the task of creating a timer that starts as soon as the browser is launched. The timer should increment every second in the format: 00:00:00 --> 00:00:01 ...

jQuery disregards the else-if statement

Currently, I am developing a web application that prompts the user to input an "application" by providing the StudentID and JobID. With the help of jQuery, I am able to notify the user if the student or job entered does not exist, if the application is alr ...

The Angular interfaces fail to load on every web browser

I am encountering an issue with my Angular and Bootstrap application where the pages are not loading. Despite checking all hooks, I am unable to identify the problem. You can access the site here. The enablers, contact, and create account buttons have be ...

Forming a jQuery element using a lengthy HTML code

Having a large HTML string that consists of multiple child nodes. Wondering if there is a way to create a jQuery DOM object from this string? Attempted to use $(string) but it only gave back an array with separate nodes. Trying to get an element that I ...

Numeric Input Box: Show gaps

I have numeric input boxes in my HTML/PHP/JS application where users will be entering numbers with 4 to 7 digits. However, I want the users to see spaces between every third digit for better readability. For instance, User types: 8000 Us ...

Launch a new window with the window.open() method and execute a function on the newly opened window

I am having trouble generating a barcode in a new window using the barcode generator script. Despite trying to use window.focus(), I can't get the barcode to appear in the new window. Any assistance on how to generate the barcode in a separate window ...

Ways to access the value of an input field using Javascript

I am currently utilizing the valums-file-uploader plugin for file uploads via ajax. However, I have encountered an issue with its functionality. Below is the script that I am using: <input type="text" id="Gaurav" name="Gaurav" /> <script src="fil ...

How can I update the color of a list item when it is clicked within a foreach loop using knockout js?

Currently, I am encountering an issue with changing the color when a user clicks on a list item using the latest version of knockout js. My goal is to change the color of a list item when it is clicked and maintain that color until another item is clicked, ...

Typescript raises an issue regarding a React component's optional prop potentially being undefined

I have a basic React component that looks like this: interface ComponentProperties { onClick?: () => void; } const CustomComponent = (properties: ComponentProperties) => { if (!properties.onClick) { return <></>; } ...