Forums > Javascript >

[TUT] How to make a Discord Bot image generator


Posts: 757

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!

no

Error: The signature must be between 3-200 characters

deadlocust

dead lotion

vip

Posts: 1744

Threads: 55

Joined: Dec, 2020

Reputation: 26

Replied

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

C# Developer [GITHUB]

platform invokes wooooooo

Shade_0122

Loli Protagonist

Posts: 1481

Threads: 99

Joined: Jun, 2020

Reputation: 19

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

 

My non skidded siggy

Posts: 757

Threads: 58

Joined: Feb, 2021

Reputation: 3

Replied

@Shade_0122

Thank you what he said

no

Error: The signature must be between 3-200 characters

Wabz

Winning.js

Posts: 2535

Threads: 193

Joined: Apr, 2020

Reputation: 24

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 :))))

My new discord is Wabz#1337 with ID 777154062789509130

Unidentified

nobody do wut i do

Posts: 401

Threads: 11

Joined: Feb, 2021

Reputation: 2

Replied

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

Learning C++, C#, JavaScript Developer

I develop random stuff

Discord: Unidentified#1091

Posts: 757

Threads: 58

Joined: Feb, 2021

Reputation: 3

Replied

@Unidentified

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

chars

no

Error: The signature must be between 3-200 characters

Unidentified

nobody do wut i do

Posts: 401

Threads: 11

Joined: Feb, 2021

Reputation: 2

Replied

@timegoesbyfast Sorry i had to lol

Learning C++, C#, JavaScript Developer

I develop random stuff

Discord: Unidentified#1091

Posts: 757

Threads: 58

Joined: Feb, 2021

Reputation: 3

Replied

@Unidentified

cough

something stuck in my throat my bad

no

Error: The signature must be between 3-200 characters

Ducxy

Eclipse Cheats, LLC.

patron

Posts: 619

Threads: 83

Joined: Mar, 2019

Reputation: 19

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.

Discord Server

Founder and CEO of Eclipse Cheats, LLC.

Full Stack Developer (C#, JS, Java, C)
































































































































































































reversed is hot

Posts: 757

Threads: 58

Joined: Feb, 2021

Reputation: 3

Replied

@Ducxy

yes i gave credits

but potato potato

no

Error: The signature must be between 3-200 characters