├── config.json ├── src ├── events │ └── ready │ │ └── console-log.js ├── commands │ ├── ping.js │ └── imagine.js ├── index.js └── models.js ├── README.md └── package.json /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "BOT_TOKEN": "", 3 | "REPLICATE_API_KEY": "" 4 | } 5 | -------------------------------------------------------------------------------- /src/events/ready/console-log.js: -------------------------------------------------------------------------------- 1 | module.exports = (client) => { 2 | console.log(`${client.user.tag} is online and ready to be used!`); 3 | }; 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Image Generator Discord Bot 2 | 3 | ## [VIDEO GUIDE](https://youtu.be/Nu-1o3rEDww) 4 | 5 | ## Technologies used: 6 | - Node.js 7 | - Discord.js 8 | - Replicate 9 | -------------------------------------------------------------------------------- /src/commands/ping.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | data: { 3 | name: 'ping', 4 | description: 'Pong!', 5 | }, 6 | 7 | run: ({ interaction, client }) => { 8 | interaction.reply(`Pong! ${client.ws.ping}ms`); 9 | }, 10 | }; 11 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ai-image-generator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "src/index.js", 6 | "scripts": { 7 | "start": "node ." 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "discord.js": "^14.9.0", 14 | "djs-commander": "^0.0.45", 15 | "replicate": "^0.11.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | const { Client, IntentsBitField } = require('discord.js'); 2 | const { CommandHandler } = require('djs-commander'); 3 | const { BOT_TOKEN } = require('../config.json'); 4 | const path = require('path'); 5 | 6 | const client = new Client({ 7 | intents: [IntentsBitField.Flags.Guilds, IntentsBitField.Flags.GuildMembers], 8 | }); 9 | 10 | new CommandHandler({ 11 | client, 12 | commandsPath: path.join(__dirname, 'commands'), 13 | eventsPath: path.join(__dirname, 'events'), 14 | }); 15 | 16 | client.login(BOT_TOKEN); 17 | -------------------------------------------------------------------------------- /src/models.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | { 3 | name: 'Stable Diffusion (Default)', 4 | value: 5 | 'stability-ai/stable-diffusion:27b93a2413e7f36cd83da926f3656280b2931564ff050bf9575f1fdf9bcd7478', 6 | }, 7 | { 8 | name: 'Openjourney (Midjourney style)', 9 | value: 10 | 'prompthero/openjourney:9936c2001faa2194a261c01381f90e65261879985476014a0a37a334593a05eb', 11 | }, 12 | { 13 | name: 'Erlich', 14 | value: 'laion-ai/erlich:92fa143ccefeed01534d5d6648bd47796ef06847a6bc55c0e5c5b6975f2dcdfb', 15 | }, 16 | { 17 | name: 'Mini DALL-E', 18 | value: 'kuprel/min-dalle:2af375da21c5b824a84e1c459f45b69a117ec8649c2aa974112d7cf1840fc0ce', 19 | }, 20 | { 21 | name: 'Waifu Diffusion', 22 | value: 'cjwbw/waifu-diffusion:25d2f75ecda0c0bed34c806b7b70319a53a1bccad3ade1a7496524f013f48983', 23 | }, 24 | ]; 25 | -------------------------------------------------------------------------------- /src/commands/imagine.js: -------------------------------------------------------------------------------- 1 | const { 2 | ApplicationCommandOptionType, 3 | EmbedBuilder, 4 | ButtonBuilder, 5 | ButtonStyle, 6 | ActionRowBuilder, 7 | } = require('discord.js'); 8 | const { REPLICATE_API_KEY } = require('../../config.json'); 9 | const models = require('../models'); 10 | 11 | module.exports = { 12 | run: async ({ interaction }) => { 13 | try { 14 | await interaction.deferReply(); 15 | 16 | const { default: Replicate } = await import('replicate'); 17 | 18 | const replicate = new Replicate({ 19 | auth: REPLICATE_API_KEY, 20 | }); 21 | 22 | const prompt = interaction.options.getString('prompt'); 23 | const model = interaction.options.getString('model') || models[0].value; 24 | 25 | const output = await replicate.run(model, { input: { prompt } }); 26 | 27 | const row = new ActionRowBuilder().addComponents( 28 | new ButtonBuilder() 29 | .setLabel(`Download`) 30 | .setStyle(ButtonStyle.Link) 31 | .setURL(`${output[0]}`) 32 | .setEmoji('1101133529607327764') 33 | ); 34 | 35 | const resultEmbed = new EmbedBuilder() 36 | .setTitle('Image Generated') 37 | .addFields({ name: 'Prompt', value: prompt }) 38 | .setImage(output[0]) 39 | .setColor('#44a3e3') 40 | .setFooter({ 41 | text: `Requested by ${interaction.user.username}`, 42 | iconURL: interaction.user.displayAvatarURL({ dynamic: true }), 43 | }); 44 | 45 | await interaction.editReply({ 46 | embeds: [resultEmbed], 47 | components: [row], 48 | }); 49 | } catch (error) { 50 | const errEmbed = new EmbedBuilder() 51 | .setTitle('An error occurred') 52 | .setDescription('```' + error + '```') 53 | .setColor(0xe32424); 54 | 55 | interaction.editReply({ embeds: [errEmbed] }); 56 | } 57 | }, 58 | 59 | data: { 60 | name: 'imagine', 61 | description: 'Generate an image using a prompt.', 62 | options: [ 63 | { 64 | name: 'prompt', 65 | description: 'Enter your prompt', 66 | type: ApplicationCommandOptionType.String, 67 | required: true, 68 | }, 69 | { 70 | name: 'model', 71 | description: 'The image model', 72 | type: ApplicationCommandOptionType.String, 73 | choices: models, 74 | required: false, 75 | }, 76 | ], 77 | }, 78 | }; 79 | --------------------------------------------------------------------------------