-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Post: How to create discord bot?
Merge pull request #10 from fredemerson/main
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
layout: ../../layouts/BlogPost.astro | ||
title: How to Create a Discord Bot? | ||
description: Learn how to create a simple discord bot | ||
pubDate: 10/20/2024 | ||
--- | ||
|
||
# How to Code a Discord bot? | ||
|
||
## 💻STEP 1 - Setting up your workspace: | ||
|
||
- Head over to the terminal of your project and type, `npm init` to set up a nodejs project. | ||
|
||
## 😃Step 2 - Add the Code: | ||
|
||
- Copy Paste the following code in your entry point, | ||
|
||
```js | ||
const express = require('express') | ||
const Discord = require('discord.js') | ||
const app = express(); | ||
|
||
app.listen(3000, () => { | ||
console.log("Project is running!"); | ||
}) | ||
|
||
const client = new Discord.Client({ intents: 32767 }) | ||
|
||
client.on('messageCreate', async (message) => { | ||
if (message.content === "hi") { | ||
message.channel.send('helllo') | ||
} | ||
}) | ||
|
||
client.login('YOUR BOT TOKEN HERE') | ||
``` | ||
|
||
- Remember to replace **YOUR BOT TOKEN HERE** with the actual token of your bot which can be obtained from [the developer portal](https://discord.com/developers/applications) | ||
|
||
## 🥇Step 3 - Running your project | ||
|
||
- You are now ready to run your project. As soon as your run your project, your discord bot should appear online and send `hello` whenever someone types `hi`. | ||
|