Skip to content

How do i make a discord bot reply multiple responses to multiple commands #6069

Closed Locked Answered by Cats3153
tommyboi1 asked this question in Q&A
Discussion options

You must be logged in to vote

call the random function inside client.on

let repliesHi = ["Hi", "Hello", "Yo", "Sup"];

client.on("message", message => {
	if (message.author.bot) return;
	if (/\bhi\b/i.test(message.content)) {
		let randomHi = Math.floor(Math.random() * repliesHi.length);
		message.channel.send(repliesHi[randomHi]);
	}
});

this way, each time the callback function for the message event is called, a new random number would be generated, instead of having it be generated one time at the beginning of the file

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by tommyboi1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants