Skip to content

Instantly share code, notes, and snippets.

@jacobhumston
Last active February 12, 2023 20:45
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacobhumston/08c5f7adf32368bb01d164faeed5acc5 to your computer and use it in GitHub Desktop.
Save jacobhumston/08c5f7adf32368bb01d164faeed5acc5 to your computer and use it in GitHub Desktop.
[Discord.Js v11.6] Random Response Examples.
//----------//
//const declarations
const Discord = require("discord.js");//created on version 11.6.3 - May break on v12+ (Have not tested on v12+.)
const bot = new Discord.Client({ disableEveryone: true });//declaring "bot" as the client.
const token = "tokenhere"//bot token goes here
const prefix = "!" //your prefix goes here
//----------//
//code
bot.on("message", async message => {//when a message is sent (that the bot can read)
if(!message.author.bot) return; //ignores if the message is by a bot
let args = message.content.trim().split(' ');//delcares the arguments
if(message.content === `${prefix}random`) {//the command
const responses = ["1", "2", "3"]; //responses - Each must be a string and separated by a comma. Example; "hi", "hello"
const reply = responses[Math.floor(Math.random() * responses.length)];//choosing a random response
message.channel.send(`Response: ${reply}`)//sends the message in the channel
}//end of the command
}//end of the message event
//----------//
bot.login(token);//login
//----------//

This is a good example for those who are new to Discord.Js and want to learn how to make a random response. You can copy and paste the code, but it will be better for you to learn how it works

This example will show you how to use a bot & a webhook to send the message. Along with an example of it being used to make pepe be mean, and random. (Note: You need to create a bot account here. Then invite it to your server.)

message.js - Normal message example. webhook.js - Webhook example. talktopepe - Pepe example.

//----------//
//const declarations
const Discord = require("discord.js");//created on version 11.6.3 - May break on v12+ (Have not tested on v12+.)
const bot = new Discord.Client({ disableEveryone: true });//declaring "bot" as the client.
const token = "tokenhere"//bot token goes here
const pepchannel = "channelid"//channel id goes here
const webhookid = "webhookid"//your pepe webhook id
const webhookpass = "webhookpass"//your pepe webhook pass
//below is what a webhook url looks like
//https://discordapp.com/api/webhooks/42837943792748923/jadsdkaskashjdkashkjshdkjaywuiryweiuyriuwej
// ^ webhookid ^ webhookpass
// [Note: This url is an example. (It will not work if used.)]
//----------//
//pepe code
bot.on("message", async message => {//when a message is sent (that the bot can read)
if (message.channel.id === `pepechannel`) {//checks if it's in your pepe channel
if(!message.author.bot) {//ignores if the message is by a bot
let channel = bot.channels.get("pepechannel")//declares "channel" as the pepe channel
let args = message.content.trim().split(' ');//delcares "args"
const responses = ["no u", "I SWEAR KAREN", "*Sad Gamer Sounds*", "My dad went to go get some milk- still got no milk", "idk who the heck karen thinks she is", "go outside", "SIT", "did u know? Jacob made this at 9 AM EVEN THO HE DID NOT SLEEP", "i swear im done with u, go eat || pie ||", "f r o g", "stop talking to me u meani", "who r u", "\n\nmom: hey how was your day? \nme: what do u think **KAREN**", "i did not ask", "meme:clap:review:clap:", `\n\nExample of a ugly avatar: \n${message.author.avatarURL}`, "MOM IM PLAYING **MINECRAFT**", "NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO",
"come'on, put **some more**", "\n\n#Relatable \nhttps://cdn.glitch.com/c95590b6-63a9-4af0-b146-591ab481bea4%2Fwhen-she-says-kiss-me-but-roblox-never-prepared-you-36358634.png", "al'right ima head out", "gimmie your minecraft account? not a bad trade", "\nme: your kids can hear u \nkaren: no they are listening to **kids pop**", ":flushed:", "...", "\n\n> **ERROR:** can't speak **stupid**", "your just mad cause it's true", "\n\nnews: America hits **1# in COVID-19** cases \namericans: **YEAH US NUMBER 1**:flag_us: :flag_us: :flag_us: :flag_us:", "sooooo.... :eyes:", "who said u could do that?", "**Rule 28390280:** Required to have atleast 10 brain cells",
"NO I JUST LOST ALL MY **V-BUCKS**", "me hate **fortnite**, as i don't play trash :wastebasket:", "JO MOMMA", "how is **joe?**", "did not ask, but sure :slight_smile:", "PLS PLS PLS", "MOM **5 MORE MINUTES!**", `:scream: **YOU GOT AN AWARD** \n\n:point_down: prize below \n|| you got nothing lol, silly ${message.author.tag}||`, "u are cool :sunglasses: ||JK||", "how's the kids doin? like you could meet anyone, lol", "nice try", "denied", `**IP** Found: || 9.${message.author.id} ||`, "how was your day?", "this chat room is cold, prrr", "yes", "no", "what's that", "it's not gay if u have socks on", "yessss", "i agree", "who's socks are those- :flushed:", "OFF",
"i wonder who let u in this channel", "r/memes", "yeah gamers", "i hope you skskskskksks-choke on the hydro flask", "im not mean im just truthful", "so you found my weakness?", ":pie:", "cats are cool", "OwO", "UwU", "i see", `${args.join(" ")}`, "HOW MAY I **HELP** YOU?", "NOBPDY CARES", "what's sad is that your talking to a bot right now, LOL **LOSER**", "so many responses, hard to choose sometimes", "wait-", "watermelone", "```Js\nmessage.channel.send(\"GET A LIFE\")```", "cool", "i **AM** cool", "im a meme", "this is pointless", "gosh so cool u r", "||**LIES**||", `${message.author} is gay`, `I'm real **I SWEAR**`, "*says bad word* **FBI OPEN UP**", "ill have u fired",
"You're very dumb.","bro shut up","shut","gosh","oml","smh","smh my head","LOL:joy::joy:","SO SUS:joy::joy::joy::joy::joy::joy::joy::joy::joy::joy::joy::joy::joy::joy::joy::joy::joy::joy::joy::joy::joy::joy::joy::joy::joy::joy:","dude",`imagine saying ${message}`,"lol #dumb :100:","okay im soo dumb with you",`i have ${responses.length} things i could say to you rn`,"BOI","girl-","okay shut","shush","zip","musty dusty and crusty",`${message} is fake info`];
//above is pepe's responses, you can make your own by doing "something here", "something here" ect in the []
//example: const responses = ["yes", "no", "ok"]; - it can be any amount of responses as long as they are separated by a comma
const pepereply = responses[Math.floor(Math.random() * responses.length)];//choosing a random response
const Webhook = new Discord.WebhookClient(webhookid, webhookpass);//find the webhook to use
//channel.setTopic(`Speak to pepe. (He can be mean.) | Responses: **${responses.length}** | Last Loser: **${message.author.tag}**`)
//above changes the channel topic, remove the // before "channel.setTopic" if you wish for this to happen
Webhook.send(`**[${message.author.tag}]** ${pepereply}`)//send the random response
}}});//end of the bot on message
//----------//
bot.login(token);//login
//----------//
//----------//
//const declarations
const Discord = require("discord.js");//created on version 11.6.3 - May break on v12+ (Have not tested on v12+.)
const bot = new Discord.Client({ disableEveryone: true });//declaring "bot" as the client.
const token = "tokenhere"//bot token goes here
const prefix = "!" //your prefix goes here
const webhookid = "webhookid"//your webhook id
const webhookpass = "webhookpass"//your webhook pass
//below is what a webhook url looks like
//https://discordapp.com/api/webhooks/42837943792748923/jadsdkaskashjdkashkjshdkjaywuiryweiuyriuwej
// ^ webhookid ^ webhookpass
// [Note: This url is an example. (It will not work if used.)]
//----------//
//code
bot.on("message", async message => {//when a message is sent (that the bot can read)
if(!message.author.bot) return; //ignores if the message is by a bot
let args = message.content.trim().split(' ');//delcares the arguments
if(message.content === `${prefix}random`) {//the command
const responses = ["1", "2", "3"]; //responses - Each must be a string and separated by a comma. Example; "hi", "hello"
const reply = responses[Math.floor(Math.random() * responses.length)];//choosing a random response
const Webhook = new Discord.WebhookClient(webhookid, webhookpass);//find the webhook to use
Webhook.send(`Response: ${reply}`);//sends the random response
}//end of the command
}//end of the message event
//----------//
bot.login(token);//login
//----------//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment