I made discord image generator bot, there are no errors so I typed node image-generate.js but no response

118 views Asked by At

This is the code from https://www.youtube.com/watch?v=k6gdwbLqD7I, The code is for making Image Generator Discord Bot, I downloaded all things required.
I copied the code just only for me, and I typed node image-generate.js on the terminal but it doesn't say anything and also bot is not online.

This is the whole code:

<kbd>
const { SlashCommandBuilder, EmbedBuilder, AttachmentBuilder } = require ('discord.js');
const superagent = require('superagent');

module.exports = {
    data: new SlashCommandBuilder()
    .setName('image-generater')
    .setDescription('provide an image using AI')
    .addStringOption(option => option.setName('prompt').setDescription('the prompt for generating your image').setRequired(true)),
    async execute (interaction) {

        await interaction.reply({ content: `loading your image.. it can take one to five minutes`, emphermal: true });

        const { options } = interaction;
        const prompt = options.getString('prompt');

        let image = await superagent.post(`https://backend.craiyon.com/generate`)
        .send({
            prompt: `${prompt}`
        });

        const buffer = Buffer.form(image.body.images[0], 'base64');
        const attachment = new AttachmentBuilder(buffer, {name: 'image.png' });

        const embed = new EmbedBuilder()
        .setColor("Blurple")
        .setImage(`'attachment://image.png`)
        .setTitle(`Image Based on: \`${prompt}\``)
        .setTimestamp() 

        await interaction.editReply({content: '', embeds: [embed], files: [attachment] });
    }
}
1

There are 1 answers

0
LarryTLlama On

The tutorial you linked appears to not actually connect to discord. This just handles any command inputs from the bot (which isn't online, so doesn't respond to anything).

I assume you've already created your bot application on the Discord Developers Portal. In order to get your bot working, you need to first:

  • Create a bot client object.
  • Define your intents and login
  • Register the command on discord

There's a great guide that goes into detail on how you do that: https://discordjs.guide/creating-your-bot/

Follow until you reach a point about handling slash commands, where you may need to modify the code to fit with a tutorial's (or vice versa). If you have any problems, feel free to drop a comment below!

Happy coding!