Categories > Coding > Javascript >

[TUT] How to make a Discord Bot image generator

Posts: 725

Threads: 58

Joined: Feb, 2021

Reputation: 3

Posted

So I will be teaching you guys how to make a discord bot that generates a image of that topic

First create a new project in your perferred IDE

Then make a bot on https://discord.com/developers

And create and application Then create the bot part

And paste this code in

https://pastebin.com/raw/P7y9yzbW

You need to install two packages reddit.images and discord.js

On default if you run the bot then say !yuri in the server that it is in it will generate a yuri anime image (You are welcome weebs)

You can change it (I am not gonna explain that because it is simple)

And yeah! Have fun

Credits: Explanation for teaching me this

Edit: Reposted pastebin link because other had a error

Enjoy!

  • 0

no

Error: The signature must be between 3-200 characters

Posts: 0

Threads: 0

Joined: ?

Reputation:

Replied

Not the best tutorial. Pasting code is not the way. You should explain what is happening in the code.

  • 0

eb_

Formally known as Shade

vip

Posts: 1045

Threads: 4

Joined: Jun, 2020

Reputation: 47

Replied

very bad tut, copy and pasting isnt the way to go, i tryed my best to explain with whats going on but i suck as at js and mostly do c# or lua but yh no

 

identifier:

const Discord = require("discord.js") //discord,js the language your building the bot
const client = new Discord.Client(); //client
const redditimage = require("reddit.images"); //able to get the images from reddit
const prefix = "!" //prefix for commands

loaded:

client.on("ready", () => { // when the client is ready/loaded
    console.log(`Logged in as ${client.user.tag}`) // prints 
});

command:

client.on('message', async message => { // when a message is sent
    let command = message.content
    const args = message.content.split(' ');
    if (message.author.bot) return;
    if (command == `${prefix}yuri`) { // if the command is the prefix and the word "yuri"
        try {
            let reddit = [
                "yuri", //try to search through reddit with tag "yuri"
                "yuri",
                "yuri"
            ]
            let subreddit = reddit[Math.floor(Math.random() * reddit.length)];
            await redditimage.fetch({
                type: "custom",
                total: 1,
                subreddit: [`${subreddit}`],
            }).then((result) => {
                message.channel.send(`Subreddit: /r/${result[0].subreddit} \nTitle name: ${result[0].title} \n ${result[0].image} \n Upvotes: ${result[0].upvotes} \n
           Downvotes: ${result[0].downvotes} \n Author: https://www.reddit.com/user/${result[0].author}/`) // posts in that channel with the title of the post, the image, the amount of upvots and downvotes and the person that posted that image
            });
        } catch (err) {
            console.log(err) // any errors found it prints it
        }
    }
});

token:

client.login("bot token here"); //turns on the client/bot with its token

 

tryed my best with explantion of each parts, someone like ducky could do better then me or someone with better js knowledge

 

  • 0

https://media.discordapp.net/attachments/1010636204225601659/1012865624797610044/sKQybOLT.gif

Posts: 725

Threads: 58

Joined: Feb, 2021

Reputation: 3

Replied

@eb_

Thank you what he said

  • 0

no

Error: The signature must be between 3-200 characters

Wabz

Winning.js

Posts: 2410

Threads: 194

Joined: Apr, 2020

Reputation: 27

Replied

hello welcome to the best tutorial ever about how to make a discord bot!

open ur IDE, you totally know what an IDE is

go to this URL and make a bot, you totally know how'

paste this code somewhere, you totally know where

instal two packages, reddit.images, discord.js, once again you definitely know how to do that if you're following the tutorial

THEN USE THE BOT

and if you wanna change it well do it yourself, im not gonna explain how and by reading this you will DEFINITELY know how to do it yourself

and we're not gonna mention the deps you gotta install thats up to you to figure out good luck :))))

  • 0

My new discord is Wabz#1337 with ID 777154062789509130

Unidentified

nobody do wut i do

Posts: 384

Threads: 11

Joined: Feb, 2021

Reputation: 2

Replied

@Wabz Thanks for this awesome tutorial! This really had some good explanation in it!!!!

  • 0

Learning C++, C#, JavaScript Developer

I develop random stuff

Discord: Unidentified#1091

Posts: 725

Threads: 58

Joined: Feb, 2021

Reputation: 3

Replied

@Unidentified

...................................

chars

  • 0

no

Error: The signature must be between 3-200 characters

Unidentified

nobody do wut i do

Posts: 384

Threads: 11

Joined: Feb, 2021

Reputation: 2

Replied

@timegoesbyfast Sorry i had to lol

  • 0

Learning C++, C#, JavaScript Developer

I develop random stuff

Discord: Unidentified#1091

Posts: 725

Threads: 58

Joined: Feb, 2021

Reputation: 3

Replied

@Unidentified

cough

something stuck in my throat my bad

  • 0

no

Error: The signature must be between 3-200 characters

Ducxy

Eclipse Cheats, LLC.

vip

Posts: 679

Threads: 103

Joined: Mar, 2019

Reputation: 37

Replied

Horrible tutorial.

 

First of all, this isn't your code. It's copied.

Second of all, this code wont even work by pasting it because you didn't tell people to install the module/package it requires.

Third, this isn't even a generator. It's a random Reddit image fetcher.

  • 0

Posts: 725

Threads: 58

Joined: Feb, 2021

Reputation: 3

Replied

@Ducxy

yes i gave credits

but potato potato

  • 0

no

Error: The signature must be between 3-200 characters

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )