π 곡λΆνλ μ§μ§μνμΉ΄λ μ²μμ΄μ§?
[Node js Project - 3] Create a Discord Bot λ³Έλ¬Έ
π©π» λ°±μλ(Back-End)/Node js
[Node js Project - 3] Create a Discord Bot
μ§μ§μνμΉ΄ 2023. 6. 17. 18:50728x90
λ°μν
<λ³Έ λΈλ‘κ·Έλ 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 λ§λ€κΈ°
π 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
λ°μν
'π©βπ» λ°±μλ(Back-End) > Node js' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Authentication in Node.js] Using Sessions & Cookies (0) | 2023.06.20 |
---|---|
[Node js Project - 4] Zoom Clone with Node JS (1) | 2023.06.18 |
[Node js Project - 2] Store Locator API (0) | 2023.06.17 |
[Node js Project - 1] Realtime Chat With Users & Rooms (0) | 2023.06.16 |
νλ‘ νΈμμ μλ²μ λ°μ΄ν° μμ²νκΈ° (Reactλ‘ fetch, axios μ¬μ©) (0) | 2023.05.18 |
Comments