Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-opus-4-20250514· AnthropicHugging Face LMArena Human Preference 140K

create me fork juniper bot in disnake or discord.JS, create multifunctional bot full code

  1. User

    create me fork juniper bot in disnake or discord.JS, create multifunctional bot full code

  2. Claude Assistant

    I'll help you create a multifunctional Discord bot. I'll provide you with a Discord.js version since it's more widely used and has excellent documentation. This bot will include multiple features like moderation, utility commands, music playback, and more.

    Here's a comprehensive Discord bot structure:

    Project Structure

    discord-bot/
    ├── src/
    │   ├── commands/
    │   │   ├── moderation/
    │   │   ├── utility/
    │   │   ├── fun/
    │   │   └── music/
    │   ├── events/
    │   ├── utils/
    │   └── index.js
    ├── config.json
    ├── package.json
    └── .env
    

    Main Bot File (src/index.js)

    const { Client, GatewayIntentBits, Collection, REST, Routes } = require('discord.js');
    const fs = require('fs');
    const path = require('path');
    require('dotenv').config();
    
    const client = new Client({
        intents: [
            GatewayIntentBits.Guilds,
            GatewayIntentBits.GuildMessages,
            GatewayIntentBits.MessageContent,
            GatewayIntentBits.GuildMembers,
            GatewayIntentBits.GuildVoiceStates,
            GatewayIntentBits.GuildMessageReactions,
            GatewayIntentBits.GuildPresences,
        ]
    });
    
    client.commands = new Collection();
    client.cooldowns = new Collection();
    client.queue = new Map();
    
    // Load commands
    const commandFolders = fs.readdirSync(path.join(__dirname, 'commands'));
    for (const folder of commandFolders) {
        const commandFiles = fs.readdirSync(path.join(__dirname, 'commands', folder)).filter(file => file.endsWith('.js'));
        for (const file of commandFiles) {
            const command = require(path.join(__dirname, 'commands', folder, file));
            client.commands.set(command.data.name, command);
        }
    }
    
    // Load events
    const eventFiles = fs.readdirSync(path.join(__dirname, 'events')).filter(file => file.endsWith('.js'));
    for (const file of eventFiles) {
        const event = require(path.join(__dirname, 'events', file));
        if (event.once) {
            client.once(event.name, (...args) => event.execute(...args));
        } else {
            client.on(event.name, (...args) => event.execute(...args));
        }
    }
    
    // Register slash commands
    const commands = [];
    client.commands.forEach(command => commands.push(command.data.toJSON()));
    
    const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);
    
    (async () => {
        try {
            console.log('Started refreshing application (/) commands.');
            await rest.put(
                Routes.applicationCommands(process.env.CLIENT_ID),
                { body: commands },
            );
            console.log('Successfully reloaded application (/) commands.');
        } catch (error) {
            console.error(error);
        }
    })();
    
    client.login(process.env.TOKEN);
    

    Event Handlers

    src/events/ready.js

    const { ActivityType } = require('discord.js');
    
    module.exports = {
        name: 'ready',
        once: true,
        execute(client) {
            console.log(`Ready! Logged in as ${client.user.tag}`);
            client.user.setActivity('with Discord.js', { type: ActivityType.Playing });
        },
    };
    

    src/events/interactionCreate.js

    const { Collection } = require('discord.js');
    
    module.exports = {
        name: 'interactionCreate',
        async execute(interaction) {
            if (!interaction.isChatInputCommand()) return;
    
            const command = interaction.client.commands.get(interaction.commandName);
            if (!command) return;
    
            const { cooldowns } = interaction.client;
            if (!cooldowns.has(command.data.name)) {
                cooldowns.set(command.data.name, new Collection());
            }
    
            const now = Date.now();
            const timestamps = cooldowns.get(command.data.name);
            const defaultCooldownDuration = 3;
            const cooldownAmount = (command.cooldown ?? defaultCooldownDuration) * 1000;
    
            if (timestamps.has(interaction.user.id)) {
                const expirationTime = timestamps.get(interaction.user.id) + cooldownAmount;
                if (now < expirationTime) {
                    const expiredTimestamp = Math.round(expirationTime / 1000);
                    return interaction.reply({ 
                        content: `Please wait, you are on a cooldown for \`${command.data.name}\`. You can use it again <t:${expiredTimestamp}:R>.`, 
                        ephemeral: true 
                    });
                }
            }
    
            timestamps.set(interaction.user.id, now);
            setTimeout(() => timestamps.delete(interaction.user.id), cooldownAmount);
    
            try {
                await command.execute(interaction);
            } catch (error) {
                console.error(error);
                await interaction.reply({ 
                    content: 'There was an error while executing this command!', 
                    ephemeral: true 
                });
            }
        },
    };
    

    Commands

    Moderation Commands

    src/commands/moderation/ban.js

    const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
    
    module.exports = {
        data: new SlashCommandBuilder()
            .setName('ban')
            .setDescription('Ban a user from the server')
            .addUserOption(option =>
                option.setName('target')
                    .setDescription('The user to ban')
                    .setRequired(true))
            .addStringOption(option =>
                option.setName('reason')
                    .setDescription('The reason for banning'))
            .setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
            .setDMPermission(false),
        async execute(interaction) {
            const target = interaction.options.getUser('target');
            const reason = interaction.options.getString('reason') ?? 'No reason provided';
    
            await interaction.guild.members.ban(target, { reason });
            await interaction.reply(`Successfully banned ${target.tag} for: ${reason}`);
        },
    };
    

    src/commands/moderation/kick.js

    const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
    
    module.exports = {
        data: new SlashCommandBuilder()
            .setName('kick')
            .setDescription('Kick a user from the server')
            .addUserOption(option =>
                option.setName('target')
                    .setDescription('The user to kick')
                    .setRequired(true))
            .addStringOption(option =>
                option.setName('reason')
                    .setDescription('The reason for kicking'))
            .setDefaultMemberPermissions(PermissionFlagsBits.KickMembers)
            .setDMPermission(false),
        async execute(interaction) {
            const target = interaction.options.getMember('target');
            const reason = interaction.options.getString('reason') ?? 'No reason provided';
    
            await target.kick(reason);
            await interaction.reply(`Successfully kicked ${target.user.tag} for: ${reason}`);
        },
    };
    

    src/commands/moderation/clear.js

    const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
    
    module.exports = {
        data: new SlashCommandBuilder()
            .setName('clear')
            .setDescription('Clear messages in a channel')
            .addIntegerOption(option =>
                option.setName('amount')
                    .setDescription('Number of messages to clear')
                    .setRequired(true)
                    .setMinValue(1)
                    .setMaxValue(100))
            .setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages)
            .setDMPermission(false),
        async execute(interaction) {
            const amount = interaction.options.getInteger('amount');
    
            await interaction.channel.bulkDelete(amount, true);
            await interaction.reply({ 
                content: `Successfully deleted ${amount} messages.`, 
                ephemeral: true 
            });
        },
    };
    

    Utility Commands

    src/commands/utility/userinfo.js

    const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
    
    module.exports = {
        data: new SlashCommandBuilder()
            .setName('userinfo')
            .setDescription('Get information about a user')
            .addUserOption(option =>
                option.setName('target')
                    .setDescription('The user to get info about')),
        async execute(interaction) {
            const target = interaction.options.getUser('target') || interaction.user;
            const member = interaction.guild.members.cache.get(target.id);
    
            const embed = new EmbedBuilder()
                .setTitle(`User Info - ${target.tag}`)
                .setThumbnail(target.displayAvatarURL({ dynamic: true }))
                .setColor(0x0099FF)
                .addFields(
                    { name: 'User ID', value: target.id, inline: true },
                    { name: 'Created At', value: `<t:${Math.floor(target.createdTimestamp / 1000)}:F>`, inline: true },
                    { name: 'Joined At', value: member ? `<t:${Math.floor(member.joinedTimestamp / 1000)}:F>` : 'N/A', inline: true },
                    { name: 'Roles', value: member ? member.roles.cache.map(r => r.toString()).join(' ') : 'N/A' }
                )
                .setTimestamp();
    
            await interaction.reply({ embeds: [embed] });
        },
    };
    

    src/commands/utility/serverinfo.js

    const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
    
    module.exports = {
        data: new SlashCommandBuilder()
            .setName('serverinfo')
            .setDescription('Get information about the server'),
        async execute(interaction) {
            const { guild } = interaction;
    
            const embed = new EmbedBuilder()
                .setTitle(`Server Info - ${guild.name}`)
                .setThumbnail(guild.iconURL({ dynamic: true }))
                .setColor(0x0099FF)
                .addFields(
                    { name: 'Server ID', value: guild.id, inline: true },
                    { name: 'Owner', value: `<@${guild.ownerId}>`, inline: true },
                    { name: 'Members', value: guild.memberCount.toString(), inline: true },
                    { name: 'Created At', value: `<t:${Math.floor(guild.createdTimestamp / 1000)}:F>`, inline: true },
                    { name: 'Boost Level', value: guild.premiumTier.toString(), inline: true },
                    { name: 'Boost Count', value: guild.premiumSubscriptionCount.toString(), inline: true }
                )
                .setTimestamp();
    
            await interaction.reply({ embeds: [embed] });
        },
    };
    

    Fun Commands

    src/commands/fun/8ball.js

    const { SlashCommandBuilder } = require('discord.js');
    
    module.exports = {
        data: new SlashCommandBuilder()
            .setName('8ball')
            .setDescription('Ask the magic 8ball a question')
            .addStringOption(option =>
                option.setName('question')
                    .setDescription('Your question')
                    .setRequired(true)),
        async execute(interaction) {
            const responses = [
                'It is certain.',
                'It is decidedly so.',
                'Without a doubt.',
                'Yes definitely.',
                'You may rely on it.',
                'As I see it, yes.',
                'Most likely.',
                'Outlook good.',
                'Yes.',
                'Signs point to yes.',
                'Reply hazy, try again.',
                'Ask again later.',
                'Better not tell you now.',
                'Cannot predict now.',
                'Concentrate and ask again.',
                "Don't count on it.",
                'My reply is no.',
                'My sources say no.',
                'Outlook not so good.',
                'Very doubtful.'
            ];
    
            const question = interaction.options.getString('question');
            const response = responses[Math.floor(Math.random() * responses.length)];
    
            await interaction.reply(`🎱 **Question:** ${question}\n**Answer:** ${response}`);
        },
    };
    

    Music Commands (Basic Structure)

    src/commands/music/play.js

    const { SlashCommandBuilder } = require('discord.js');
    const { joinVoiceChannel, createAudioPlayer, createAudioResource } = require('@discordjs/voice');
    const ytdl = require('ytdl-core');
    
    module.exports = {
        data: new SlashCommandBuilder()
            .setName('play')
            .setDescription('Play a song from YouTube')
            .addStringOption(option =>
                option.setName('url')
                    .setDescription('The YouTube URL')
                    .setRequired(true)),
        async execute(interaction) {
            const url = interaction.options.getString('url');
            const voiceChannel = interaction.member.voice.channel;
    
            if (!voiceChannel) {
                return interaction.reply('You need to be in a voice channel to play music!');
            }
    
            const permissions = voiceChannel.permissionsFor(interaction.client.user);
            if (!permissions.has('Connect') || !permissions.has('Speak')) {
                return interaction.reply('I need permissions to join and speak in your voice channel!');
            }
    
            try {
                const connection = joinVoiceChannel({
                    channelId: voiceChannel.id,
                    guildId: interaction.guild.id,
                    adapterCreator: interaction.guild.voiceAdapterCreator,
                });
    
                const stream = ytdl(url, { filter: 'audioonly' });
                const resource = createAudioResource(stream);
                const player = createAudioPlayer();
    
                player.play(resource);
                connection.subscribe(player);
    
                await interaction.reply(`Now playing: ${url}`);
            } catch (error) {
                console.error(error);
                await interaction.reply('There was an error playing the song!');
            }
        },
    };
    

    Configuration Files

    package.json

    {
      "name": "discord-multifunctional-bot",
      "version": "1.0.0",
      "description": "A multifunctional Discord bot",
      "main": "src/index.js",
      "scripts": {
        "start": "node src/index.js",
        "dev": "nodemon src/index.js"
      },
      "dependencies": {
        "discord.js": "^14.14.1",
        "@discordjs/voice": "^0.16.1",
        "@discordjs/opus": "^0.9.0",
        "dotenv": "^16.3.1",
        "ytdl-core": "^4.11.5",
        "ffmpeg-static": "^5.2.0"
      },
      "devDependencies": {
        "nodemon": "^3.0.2"
      }
    }
    

    .env

    TOKEN=YOUR_BOT_TOKEN_HERE
    CLIENT_ID=YOUR_CLIENT_ID_HERE
    

    config.json

    {
      "prefix": "!",
      "embedColor": "#0099ff",
      "errorColor": "#ff0000",
      "successColor": "#00ff00"
    }
    

    Setup Instructions

    1. Create a new directory and initialize the project:
    mkdir discord-bot
    cd discord-bot
    npm init -y
    
    1. Install dependencies:
    npm install discord.js @discordjs/voice @discordjs/opus dotenv ytdl-core ffmpeg-static
    npm install -D nodemon
    
    1. Create the folder