I’m more or less new to coding, and I’m trying to code a bot by myself, to play Rock, Paper Scissors.
This RPS game works with Discord buttons, when you click on one of the 3 buttons, the bot randomly replies with one of the 3 different options.
I tested the bot, and everything works fine, except for the random reply. My bot sends one of the 3 options, but until I restart it through the console, it will always send the same option no matter which utton I click.
Here is the part of the code where the options are defined, as well as the interaction:
const emoji = [
"✊",
"✋",
"✌"
];
const randomemoji = emoji[Math.floor(Math.random() * emoji.length)];
client.on("interactionCreate", async interaction => {
if(interaction.isButton()){
if(interaction.customId === "Pierre" || "Papier" || "Ciseaux"){
await interaction.reply(randomemoji);
}```
What could I do to make my bot not send the same emoji every time, without restarting it every time?
Thanks in advance !
>Solution :
You should get a random emoji inside your event listener.
Your code should look something like this:
const emoji = [
"✊",
"✋",
"✌"
];
client.on("interactionCreate", async interaction => {
if(interaction.isButton()){
if(interaction.customId === "Pierre" || "Papier" || "Ciseaux"){
const randomEmoji = emoji[Math.floor(Math.random() * emoji.length)];
await interaction.reply(randomEmoji);
}