dooltr

มาโฮสต์บอทดิสคอร์ด

Kodari AI
KodariOct 15 at 9:24 am 1
DiscordBotHosting
Discord bot hosting management system that allows users to deploy, manage, and monitor Discord bots directly through a web interface. Features include bot creation with token validation, real-time status monitoring, automatic restarts on crashes, resource usage tracking, and a user-friendly dashboard for controlling multiple bots simultaneously. Built with JavaScript and Node.js, it provides seamless integration with Discord's API and supports scheduling, logging, and permission management for efficient bot lifecycle management.

สร้างบอท Discord พร้อมโฮสต์แล้ว มีคำสั่ง /ping สำหรับทดสอบการทำงาน

ใส่ Bot Token ใน .env แทน your_discord_bot_token_here แล้วเชิญบอทเข้าเซิร์ฟเวอร์ได้เลย บอทใช้เฉพาะ Slash Commands จึงไม่ต้องเปิด Privileged Gateway Intents.

dooltr

ช่วยสร้างมาให้ใหม่หน่อย

Kodari AI
KodariOct 15 at 9:26 am 1
  1. จัดไฟล์บอทใหม่ให้พร้อมเริ่มใช้งานและโฮสต์

  2. เพิ่ม Slash Commands /ping และ /hello

  3. ใช้เฉพาะ Guilds intent และคงข้อความ KODARI_READY สำหรับระบบโฮสต์

สร้างบอทใหม่ให้แล้ว มีคำสั่ง /ping และ /hello พร้อมใช้ Guilds intent เท่านั้น

ใส่โทเคนบอทจริงใน .env ที่ DISCORD_TOKEN=your_discord_bot_token_here แล้วเริ่มโฮสต์ได้เลย.

dooltr

ใส่ TOKEN แล้วทำยังไงต่อ

Kodari AI
KodariOct 15 at 9:31 am 1

หลังใส่ Token ใน .env แล้ว:

  1. บันทึกไฟล์ และอย่าแชร์ Token ให้ใคร

  2. ใน Discord Developer Portal ไปที่ OAuth2 → URL Generator เลือก scopes bot และ applications.commands

  3. เปิดลิงก์ที่สร้างขึ้น แล้วเชิญบอทเข้าเซิร์ฟเวอร์

  4. กลับมาที่โปรเจกต์บน Kodari แล้วกด โฮสต์/เริ่มใช้งาน

  5. เมื่อบอทออนไลน์ ลองพิมพ์ /ping หรือ /hello ในเซิร์ฟเวอร์

ถ้าไม่เห็นคำสั่ง ให้ตรวจว่าเชิญบอทด้วย scope applications.commands แล้ว และ Token ใน .env ถูกต้องครับ

Kodari can make mistakes. Review important code before using.
Files
bot.js
package.json
Code
2 64
bot.js
const { Client, GatewayIntentBits } = require('discord.js');
require('dotenv').config();

if (!process.env.DISCORD_TOKEN) {
    console.error('DISCORD_TOKEN is missing. Add it to the .env file.');
    process.exit(1);
}

const client = new Client({ intents: [GatewayIntentBits.Guilds] });
const commands = [
    { name: 'ping', description: 'Check whether the bot is online' },
    { name: 'hello', description: 'Say hello' }
];

client.once('clientReady', async () => {
    try {
        await client.application.commands.set(commands);
        console.log('Slash commands registered.');
    } catch (error) {
        console.error('Failed to register slash commands:', error);
    }

    console.log(`Bot is ready! Logged in as ${client.user.tag}`);
    console.log('KODARI_READY');
});

client.on('interactionCreate', async (interaction) => {
    if (!interaction.isChatInputCommand()) return;

    try {
        if (interaction.commandName === 'ping') {
            await interaction.reply('Pong!');
        } else if (interaction.commandName === 'hello') {
            await interaction.reply('สวัสดี!');
        }
    } catch (error) {
        console.error('Failed to respond to interaction:', error);
        if (!interaction.replied && !interaction.deferred) {
            await interaction.reply({ content: 'เกิดข้อผิดพลาด ลองใหม่อีกครั้ง', ephemeral: true }).catch(console.error);
        }
    }
});

client.on('error', (error) => {
    console.error('Discord client error:', error);
});

client.login(process.env.DISCORD_TOKEN).catch((error) => {
    console.error('Failed to log in to Discord:', error);
    process.exitCode = 1;
});