How to create a Discord bot using Bun:

  1. Install the necessary dependencies:
1
bun add discord.js
  1. Create a new file, let’s say bot.js, and add the following code:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
const Discord = require('discord.js');
const client = new Discord.Client();

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

client.on('message', msg => {
  if (msg.content === 'ping') {
    msg.reply('Pong!');
  }
});

client.login('YOUR_DISCORD_BOT_TOKEN');
  1. Replace 'YOUR_DISCORD_BOT_TOKEN' with your actual Discord bot token. You can obtain a token by creating a new bot on the Discord Developer Portal.

  2. Save the file and run it using Node.js:

1
node bot.js
  1. Your bot should now be online and ready to respond to the “ping” command with “Pong!”.

Remember to customize the bot’s behavior and add more functionality as needed.