😎 κ³΅λΆ€ν•˜λŠ” μ§•μ§•μ•ŒνŒŒμΉ΄λŠ” μ²˜μŒμ΄μ§€?

[Node js Project - 3] Create a Discord Bot λ³Έλ¬Έ

πŸ‘©‍πŸ’» λ°±μ—”λ“œ(Back-End)/Node js

[Node js Project - 3] Create a Discord Bot

μ§•μ§•μ•ŒνŒŒμΉ΄ 2023. 6. 17. 18:50
728x90
λ°˜μ‘ν˜•

<λ³Έ λΈ”λ‘œκ·ΈλŠ” Traversy Media μ˜ 유튜브λ₯Ό μ°Έκ³ ν•΄μ„œ κ³΅λΆ€ν•˜λ©° μž‘μ„±ν•˜μ˜€μŠ΅λ‹ˆλ‹€ :-)>

=> Create a Discord Bot With Node.js

 

🌏 개발 ν™˜κ²½ μ„€μ •

npm init

npm install -D nodemon

npm i discord.js

npm i dotenv

 

🏠 package.json

{
  "name": "discordbot",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node server.js",
    "dev": "nodemon server.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "nodemon": "^2.0.22"
  },
  "dependencies": {
    "discord.js": "^14.11.0",
    "dotenv": "^16.3.0"
  }
}

 

🌏 Discord Bot

https://discord.com/developers/applications/

 

🏠 Bot λ§Œλ“€κΈ°

Token copy~~~~~~~~~~ ν•΄μ„œ .env 에 λ„£κΈ°

 

🏠 Bot κ³Ό μ±„νŒ…μ°½ λ§Œλ“€κΈ°

url μ°Έκ³ ν•˜μ„Έμš©

 

🏠 src/bot.js

Discord.js v14:
const Discord = require("discord.js");

const client = new Discord.Client({
  intents: [
    Discord.GatewayIntentBits.Guilds,
    Discord.GatewayIntentBits.GuildMessages,
  ],
});
require("dotenv").config();

const Discord = require("discord.js");

const client = new Discord.Client({
  intents: [
    Discord.GatewayIntentBits.Guilds,
    Discord.GatewayIntentBits.GuildMessages,
  ],
});

client.on("ready", () => {
  console.log(`${client.user.tag} has logged in`);
});

client.login(process.env.DISCORDJS_BOT_TOKEN);

 

🌏 μ‹€ν–‰ν™”λ©΄

🏠 src/bot.js

require("dotenv").config();

const Discord = require("discord.js");

const client = new Discord.Client({
  intents: [
    Discord.GatewayIntentBits.Guilds,
    Discord.GatewayIntentBits.GuildMessages,
  ],
});

client.on("ready", () => {
  console.log(`${client.user.tag} has logged in`);
});

client.on("message", (message) => {
  if (message.author.bot) return;

  console.log(`[${message.author.tag}] : ${message.content}`);

  if (message.content === "hello") {
    message.channel.send("hello there!");
  }
});

client.login(process.env.DISCORDJS_BOT_TOKEN);

 

728x90
λ°˜μ‘ν˜•
Comments