๐Ÿค– ๋””์Šค์ฝ”๋“œ ๋ด‡ ๊ฐœ๋ฐœ์ผ์ง€ - 1

eastminnยท2022๋…„ 3์›” 21์ผ
0

๐Ÿค–Discord

๋ชฉ๋ก ๋ณด๊ธฐ
1/3
post-thumbnail

๐Ÿ“š ๋””์Šค์ฝ”๋“œ ๋ด‡ ์ƒ์„ฑ ๋ฐ ๊ฐ„๋‹จํ•œ ๋ช…๋ น์–ด ๋ฐ˜์‘, ์ž„๋ฒ ๋“œ

Python ๊ณผ git ์— ๋Œ€ํ•ด ๊ณต๋ถ€ํ• ๊ฒธ ํŒŒ์ด์ฌ์šฉ ๋””์Šค์ฝ”๋“œ ๋ด‡ API์ธ discord.py ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐœ๋ฐœ์„ ํ–ˆ๋‹ค.

์ผ๋‹จ git์„ ํ†ตํ•ด ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•  ์ €์žฅ์†Œ๋ฅผ ๋งŒ๋“ค์–ด์คฌ๋‹ค.

๊ทธ๋ฆฌ๊ณ  ๋””์Šค์ฝ”๋“œ ๋ด‡์„ ๊ฐœ๋ฐœํ•˜๊ธฐ ์œ„ํ•ด cmd์ฐฝ์—์„œ discord.py๋ฅผ ์„ค์น˜ํ•ด์คฌ๋‹ค.

๋””์Šค์ฝ”๋“œ ๋ด‡์„ ์ƒ์„ฑํ•˜๋ฉด ์ดˆ๊ธฐ์—๋Š” ์˜คํ”„๋ผ์ธ ์ƒํƒœ์ธ๋ฐ

import discord, asyncio

client = discord.Client()

@client.event
async def on_ready():

์ด๋Ÿฐ์‹์œผ๋กœ ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•ด์ค€๋‹ค๋ฉด ๋ด‡์ด ์˜จ๋ผ์ธ ์ƒํƒœ๊ฐ€ ๋  ๊ฒƒ์ด๋‹ค.

์ด์ œ ์œ ์ €๊ฐ€ ์ฑ„ํŒ…์ฐฝ์— ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๋ด‡์ด ํŠน์ • ๋ฉ”์„ธ์ง€๋ฅผ ์ถœ๋ ฅํ•˜๋„๋ก ํ•ด์ค„ ๊ฒƒ์ด๋‹ค.

@client.event
async def on_message(message):
    if message.content == "!์ธ์‚ฌ": # ๋ฉ”์„ธ์ง€๋ฅผ ๊ฐ์ง€ํ•œ๋‹ค.
        await message.channel.send ("{} | {}๋‹˜ ์•ˆ๋…•ํ•˜์„ธ์š”!".format(message.author, message.author.mention)) # ์ž‘์„ฑ๋œ ์ฑ„๋„์— ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ
        await message.author.send ("{} | {}๋‹˜ ์•ˆ๋…•ํ•˜์„ธ์š”!".format(message.author, message.author.mention)) # ์ž‘์„ฑํ•œ ์œ ์ €์—๊ฒŒ DM์œผ๋กœ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ

message.author ์€ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•œ ์œ ์ €์˜ ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ๊ฒƒ์ด๊ณ ,
message.author.mention ์€ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•œ ์œ ์ €๋ฅผ ํƒœ๊ทธํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

์ด๋Ÿฐ์‹์œผ๋กœ ๋ด‡์ด ๋ฉ”์„ธ์ง€๋ฅผ ๋ณด๋‚ด๊ฒŒ ๋œ๋‹ค.

์ด์ œ '!์ •๋ณด'๋ฅผ ์ž…๋ ฅํ•˜๋ฉด
์ด๋Ÿฐ ์‹์œผ๋กœ ๋ด‡์˜ ์ •๋ณด๊ฐ€ ๋„์›Œ์ง€๋„๋ก ๋งŒ๋“ค์–ด์ค„ ๊ฒƒ์ธ๋ฐ ๊ฐ€๋…์„ฑ์„ ์ข‹๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด์„œ ๋ด‡์˜ ๋ฉ”์„œ์ง€ ์ถœ๋ ฅํ˜•์‹์ธ ์ž„๋ฒ ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด ์ค„ ๊ฒƒ์ด๋‹ค.

if message.content == "!์ •๋ณด": # '!์ •๋ณด'๋ฅผ ์ž…๋ ฅํ•œ๋‹ค๋ฉด
        embed = discord.Embed(title="๊ณ ๋จ๋ฏธ", description="ํ”„๋กœ์ ํŠธ์šฉ์œผ๋กœ ๊ฐœ๋ฐœ์ค‘์ธ ๋ด‡",timestamp=datetime.datetime.now(pytz.timezone('UTC')), color=0x00ff00)
        embed.add_field(name="๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ๋“ค ์ถ”๊ฐ€ ์˜ˆ์ •", value="์‹œ๊ฐ„๋‚  ๋–„๋งˆ๋‹ค ์ถ”๊ฐ€ํ•  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.", inline=False)
        embed.set_footer(text="Bot Made by. ๊น€๋™๋ฏผ#0026", icon_url="https://cdn.discordapp.com/attachments/955360993729449987/955392163158569021/IMG_20220320_042000_013.jpg")
        embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/955360993729449987/955392404280737812/99pk9saw36t7q8t3o0gt.jpg")
    
        await message.channel.send(embed=embed) # ๋ฉ”์„ธ์ง€๋ฅผ ์ฑ„ํŒ…๋ฐฉ์— ์ถœ๋ ฅํ•œ๋‹ค.

์ด๋Ÿฐ์‹์œผ๋กœ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ–ˆ๋‹ค.

๋งŒ์•ฝ inline์„ True๋กœ ํ•œ๋‹ค๋ฉด ์ž„๋ฒ ๋“œ ๋ผ์ธ์ด ์ค„๋ฐ”๊ฟˆ๋˜์ง€์•Š๊ณ  ์ถœ๋ ฅ๋  ๊ฒƒ์ด๋‹ค.

๋งˆ์ง€๋ง‰์œผ๋กœ git ์„ ํ†ตํ•ด์„œ github๋กœ ๋‚ด ์ฝ”๋“œ๋ฅผ ๋ณด๋‚ด์คฌ๋‹ค.

์ฝ”๋“œ๋ฅผ ์ปค๋ฐ‹ํ•˜๋‹ˆ ๋””์Šค์ฝ”๋“œํŒ€์˜ ๊ณต์‹ ๋ฉ”์„ธ์ง€๋กœ ๋‚ด๊ฐ€ ์ƒ์„ฑํ•œ ๋ด‡์˜ ํ† ํฐ์ด ์œ ์ถœ๋๋‹ค๊ณ  ๋ฉ”์„ธ์ง€๊ฐ€ ์™”๋‹ค. ๋‹ค์Œ๋ถ€ํ„ด ์กฐ์‹ฌํžˆ ํ† ํฐ ๋ถ€๋ถ„์€ ์ œ์™ธํ•˜๊ณ  ์ฝ”๋“œ๋ฅผ ์˜ฌ๋ ค์•ผ๊ฒ ๋‹ค.

profile
๐Ÿช– 22.06.21 ~ 23.12.21

2๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2022๋…„ 3์›” 21์ผ

๋ฉ‹์ง€๋„ค์š”!

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ
comment-user-thumbnail
4์ผ ์ „

๋ฉ‹์ง‘๋‹ˆ๋‹ค!

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ