Try the Gemini Bot by adding to your discord server : Click here to Add
After adding the bot to your discord server then you can simply tag the bot and ask question as below after which you will get your answers shortly 😉

The Bot won't give any response as currently it only works locally. Will host soon at Replit:D
Execute this commands on your IDE on a directory you want to work on
npm initnpm install discord.jsnpm install @google/generative-ai
After doing this:
- Get Discord API Key via : https://discord.com/developers/applications
After you create a API key then you will get to see a token once so you should copy that and keep it safely somewhere, better to use Google Keep - https://keep.google.com/ for this.
- Get Gemini API Key via: https://makersuite.google.com/
And to view your already created API key, you can visit: https://aistudio.google.com/app/apikey
And keep both the keys at .env file:-
DISCORD_API_KEY= # Your Discord API key
GEMINI_API_KEY= # Your Gemini API key
But make sure to include .env file to your .gitignore file
And then enter this code at index.js file
require("dotenv").config();
const { Client, GatewayIntentBits } = require("discord.js");
const { GoogleGenerativeAI } = require("@google/generative-ai");
const MODEL_NAME = "gemini-pro";
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
client.on("ready", () => {
console.log("Bot is ready!");
});
client.on("messageCreate", async (message) => {
if (message.author.bot) return;
if (message.mentions.has(client.user)) {
const userMessage = message.content
.replace(`<@!${client.user.id}>`, "")
.trim();
const model = genAI.getGenerativeModel({ model: MODEL_NAME });
const generationConfig = {
temperature: 0.9,
topK: 1,
topP: 1,
maxOutputTokens: 2048,
};
const parts = [
{
text: `input: ${userMessage}`,
},
];
const result = await model.generateContent({
contents: [{ role: "user", parts }],
generationConfig,
});
const reply = await result.response.text();
// due to Discord limitations, we can only send 2000 characters at a time, so we need to split the message
if (reply.length > 2000) {
const replyArray = reply.match(/[\s\S]{1,2000}/g);
replyArray.forEach(async (msg) => {
await message.reply(msg);
});
return;
}
message.reply(reply);
}
});
client.login(process.env.DISCORD_API_KEY);And finally
node index.jsYou will see this output if everthing is working fine:
Bot is ready!
The Bot only works if your process is running which means if you stop the process then the bot won't give you response.
Then after setting up OAuth2 from your Discord Developer Dashboard you will be able to invite the bot.
Some guides to follow at Discord Developer Dashboard:-
- At
OAuth2 URL Generatorchoosebot
- Give Necessary Bot Permissions

- After this you will get a Generated URL for bot invite.

Congrats on making your own Gemini Bot.
Thank you for Reading till the end, I wish to see your own bot live.
Do let me know if you have any issues at GDG Kathmandu Discord Server
- https://razanfawwaz.medium.com/membuat-chatbot-discord-dengan-palm-api-0a041dcd9bc0
- https://github.com/razanfawwaz/gemini-bot?tab=readme-ov-file
- https://ai.google.dev/tutorials/node_quickstart#generate-text-from-text-input
- https://discordjs.guide/preparations/#installing-node-js
- https://ai.google.dev/tutorials/node_quickstart#generate-text-from-text-input