Skip to content

Commit

Permalink
Added repository link at end of posts
Browse files Browse the repository at this point in the history
  • Loading branch information
sunwoo-j committed Jun 27, 2024
1 parent a4f779b commit 2f140ba
Show file tree
Hide file tree
Showing 7 changed files with 643 additions and 592 deletions.
5 changes: 3 additions & 2 deletions _drafts/2024-06-26-discord-bot-7.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
title: 디스코드 봇 DIY - 7. 엑셀로 데이터베이스 구축하기
title: 디스코드 봇 DIY - 7. SQLite로 데이터베이스 구축하기
date: 2024-06-25 16:48:09 +/-TTTT
last_modified_at: 2024-06-25 16:48:09 +/-TTTT
categories: [Python, discord.py]
tags: [python, discord, bot, database]
tags: [python, discord, bot, database, sqlite]
description: 엑셀로 데이터 저장하고 불러오기
---

> 이 글에서 다루는 내용
> - Embed 활용해서 메시지 출력하기
50 changes: 29 additions & 21 deletions _posts/2024-05-22-discord-bot-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,38 +267,46 @@ client.run(TOKEN)
## 부록

### i. 전체 코드
<details>
<summary>코드 보기</summary>
<div markdown="1">
```python
# bot.py
import os, discord
from dotenv import load_dotenv

```python
# bot.py
import os, discord
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('BOT_TOKEN')

load_dotenv()
TOKEN = os.getenv('BOT_TOKEN')
intents = discord.Intents.all()

intents = discord.Intents.all()
client = discord.Client(intents=intents)

client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f'{client.user}(으)로 접속했습니다.')

@client.event
async def on_ready():
print(f'{client.user}(으)로 접속했습니다.')
@client.event
async def on_message(message):
if message.author == client.user:
return

@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$hello'):
await message.channel.send('Hello!')

if message.content.startswith('$hello'):
await message.channel.send('Hello!')

client.run(TOKEN)
```
client.run(TOKEN)
```
</div>
</details>

### ii. 폴더 구조

```tree
📦Discord Bot
┣ 📜.env
┗ 📜bot.py
```
```

### iii. 깃허브 리포지토리

<https://github.com/sunwoo-j/discord-bot-diy>
86 changes: 47 additions & 39 deletions _posts/2024-05-24-discord-bot-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,49 +150,57 @@ async def multiply_error(ctx, error):
## 부록

### i. 전체 코드

```python
# bot.py
import os, discord
from discord.ext import commands
from dotenv import load_dotenv

load_dotenv()
TOKEN = os.getenv('BOT_TOKEN')

intents = discord.Intents.all()

bot = commands.Bot(command_prefix='$', intents=intents)

@bot.event
async def on_ready():
print(f'{bot.user}(으)로 접속했습니다.')

@bot.command(name='hello', help="인사를 합니다")
async def hello(ctx):
await ctx.send("Hello!")

@bot.command(name='곱하기', help="숫자 두 개를 곱합니다")
async def multiply(ctx, first_int: int, second_int: int):
await ctx.send(f"결과는 {product}입니다.")

@bot.command(name='참가일', help="멤버의 서버 참가 날짜를 알려줍니다")
async def joined(ctx, member: discord.Member):
join_date = member.joined_at.strftime("%Y-%m-%d")
await ctx.send(f"{member.display_name}님은 {join_date}에 서버에 참가했습니다.")

@multiply.error
async def multiply_error(ctx, error):
if isinstance(error, commands.BadArgument):
await ctx.send("오류: 정수 두 개를 입력해 주세요.")

bot.run(TOKEN)
```
<details>
<summary>코드 보기</summary>
<div markdown="1">
```python
# bot.py
import os, discord
from discord.ext import commands
from dotenv import load_dotenv

load_dotenv()
TOKEN = os.getenv('BOT_TOKEN')

intents = discord.Intents.all()

bot = commands.Bot(command_prefix='$', intents=intents)

@bot.event
async def on_ready():
print(f'{bot.user}(으)로 접속했습니다.')

@bot.command(name='hello', help="인사를 합니다")
async def hello(ctx):
await ctx.send("Hello!")

@bot.command(name='곱하기', help="숫자 두 개를 곱합니다")
async def multiply(ctx, first_int: int, second_int: int):
await ctx.send(f"결과는 {product}입니다.")
@bot.command(name='참가일', help="멤버의 서버 참가 날짜를 알려줍니다")
async def joined(ctx, member: discord.Member):
join_date = member.joined_at.strftime("%Y-%m-%d")
await ctx.send(f"{member.display_name}님은 {join_date}에 서버에 참가했습니다.")

@multiply.error
async def multiply_error(ctx, error):
if isinstance(error, commands.BadArgument):
await ctx.send("오류: 정수 두 개를 입력해 주세요.")

bot.run(TOKEN)
```
</div>
</details>

### ii. 폴더 구조

```tree
📦Discord Bot
┣ 📜.env
┗ 📜bot.py
```
```

### iii. 깃허브 리포지토리

<https://github.com/sunwoo-j/discord-bot-diy>
114 changes: 61 additions & 53 deletions _posts/2024-05-27-discord-bot-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,64 +165,72 @@ async def on_member_join(member):
## 부록

### i. 전체 코드

```python
# bot.py
import os, discord
from discord.ext import commands
from dotenv import load_dotenv

load_dotenv()
TOKEN = os.getenv('BOT_TOKEN')
GUILD = int(os.getenv('GUILD_ID'))
CHANNEL = int(os.getenv('CHANNEL_ID'))
welcome_channel = {GUILD:CHANNEL} # 길드별 환영 메시지 전송 채널

intents = discord.Intents.all()

bot = commands.Bot(command_prefix='$', intents=intents)

@bot.event
async def on_ready():
guild = discord.utils.find(lambda g: g.id == GUILD, bot.guilds)
print(
f"{bot.user}(으)로 접속했습니다.\n"
f"접속 길드: {guild.name} (ID: {guild.id})"
)

@bot.event
async def on_member_join(member):
guild_id = welcome_channel.get(member.guild.id, None)
if guild_id is not None:
channel = bot.get_channel(guild_id)
await channel.send(f"{member.display_name}님이 서버에 참가하셨습니다.")

@bot.command(name='hello', help="인사를 합니다")
async def hello(ctx):
await ctx.send("Hello!")

@bot.command(name='곱하기', help="숫자 두 개를 곱합니다")
async def multiply(ctx, first_int: int, second_int: int):
product = first_int * second_int
await ctx.send(f"결과는 {product}입니다.")

@multiply.error
async def multiply_error(ctx, error):
if isinstance(error, commands.BadArgument):
await ctx.send("오류: 정수 두 개를 입력해 주세요.")
<details>
<summary>코드 보기</summary>
<div markdown="1">
```python
# bot.py
import os, discord
from discord.ext import commands
from dotenv import load_dotenv

load_dotenv()
TOKEN = os.getenv('BOT_TOKEN')
GUILD = int(os.getenv('GUILD_ID'))
CHANNEL = int(os.getenv('CHANNEL_ID'))
welcome_channel = {GUILD:CHANNEL} # 길드별 환영 메시지 전송 채널

intents = discord.Intents.all()

bot = commands.Bot(command_prefix='$', intents=intents)

@bot.event
async def on_ready():
guild = discord.utils.find(lambda g: g.id == GUILD, bot.guilds)
print(
f"{bot.user}(으)로 접속했습니다.\n"
f"접속 길드: {guild.name} (ID: {guild.id})"
)
@bot.command(name='참가일', help="멤버의 서버 참가 날짜를 알려줍니다")
async def joined(ctx, member: discord.Member):
join_date = member.joined_at.strftime("%Y-%m-%d")
await ctx.send(f"{member.display_name}님은 {join_date}에 서버에 참가했습니다.")

bot.run(TOKEN)
```
@bot.event
async def on_member_join(member):
guild_id = welcome_channel.get(member.guild.id, None)
if guild_id is not None:
channel = bot.get_channel(guild_id)
await channel.send(f"{member.display_name}님이 서버에 참가하셨습니다.")

@bot.command(name='hello', help="인사를 합니다")
async def hello(ctx):
await ctx.send("Hello!")

@bot.command(name='곱하기', help="숫자 두 개를 곱합니다")
async def multiply(ctx, first_int: int, second_int: int):
product = first_int * second_int
await ctx.send(f"결과는 {product}입니다.")

@multiply.error
async def multiply_error(ctx, error):
if isinstance(error, commands.BadArgument):
await ctx.send("오류: 정수 두 개를 입력해 주세요.")
@bot.command(name='참가일', help="멤버의 서버 참가 날짜를 알려줍니다")
async def joined(ctx, member: discord.Member):
join_date = member.joined_at.strftime("%Y-%m-%d")
await ctx.send(f"{member.display_name}님은 {join_date}에 서버에 참가했습니다.")

bot.run(TOKEN)
```
</div>
</details>

### ii. 폴더 구조

```tree
📦Discord Bot
┣ 📜.env
┗ 📜bot.py
```
```

### iii. 깃허브 리포지토리

<https://github.com/sunwoo-j/discord-bot-diy>
Loading

0 comments on commit 2f140ba

Please sign in to comment.