New to Coding need Help please

I am very new to coding and would like help on this plz?

const Discord = require('discord.js');
const client = new Discord.Client();

const prefix = '?';
client.on('message', message => {
    if (message.content == "word") { const replies = ["reply1", "reply2"] (message,replytext = Math.floor((Math.random() * replies.length) + 0) (message.channel.send(replies[message.replytext]); }
});

client.login('token')

MOD EDIT: formatting

Hey @FS-worldfamous I think anyone who wanted to offer any help would probably need more information. What specific problem are you running into while you’re working on this?

I see at least one thing wrong with this, at least the way I do things. You shouldn’t set the properties of message, like you did with message.replytext. Instead create a new variable to use, like this:

const Discord = require('discord.js'); 
const client = new Discord.Client(); 
const prefix = '?'; 
client.on('message', message => { 
if (message.content == "word") { 
const replies = ["reply1", "reply2"] 
let replytext = Math.floor((Math.random() * replies.length) + 0)
message.channel.send(replies[replytext]); 
}
});
client.login('token')

WOW! It works awesome! But! seems to be replying to itself i get double messages? i added one more reply to it and does randomly double messages? i did add the toLowerCase() and wonder if that or the added 3rd reply is making the double reply? Still testing it. But Really thx you so much for taking the time to help me out with this. I’m learning more and more everyday and can’t thank you enough for your help!
YOU SO ROCK!

1 Like

yeah, it will reply to itself with the current code.
Add if(message.author.bot) return under the client.on('message', message => { and it won’t do that anymore, as well as not respond to any bots to avoid getting in a loop

Glad you were helped by it! Feel free to use the “thank for helping” feature on glitch.com to thank me :slight_smile:

WOW again thx you so so much just got back from store was gonna look up that code. Again thank you for taking the time in helping me with my discord bot development with your help i am gaining a better understanding of coding. I truly and sincerely am i gratitude and debt to you for your help i hope your day is as awesome as you made mine!

I am so so sorry! the problem was on my end. I had made changes to the Index.js shortly after all this and everything was coming back double? undid everything i change and still had the same issue? after hours of trying to figure it out i decided to shut the bot complete down and restarted it. Everything went back to normal, remade the page of your code and it’s function is perfect! Even adding in 2 more replies it works perfect! Thx you again and will give thanks in glitch, just figure out how to do that lol

1 Like