discord.py ํ”„๋กœ์ ํŠธ 2: Welcomer ๐Ÿ‘‹๐Ÿฝ

6767 ๋‹จ์–ด discordpythondiscordpy
์ด ๊ธฐ์‚ฌ์—์„œ๋Š” ํ™˜์˜ ๋ด‡์„ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์„ ๋ฐฐ์šฐ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค!

์‚ฌ์šฉ์ž์˜ ์•„๋ฐ”ํƒ€์™€ ์ด๋ฆ„์œผ๋กœ ์ง€์ •๋œ ์ฑ„๋„์— ํ™˜์˜ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋ƒ…๋‹ˆ๋‹ค!


์‹œ์ž‘ํ•˜๋ ค๋ฉด ๋ด‡์„ ์ดˆ๊ธฐํ™”ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด ์—ฐ์Šต์—์„œ๋Š” ๋ช…๋ น์ด ์—†๊ธฐ ๋•Œ๋ฌธ์— commands.Bot ๋Œ€์‹  discord.Client๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

import discord

client = discord.Client()


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

import discord

client = discord.Client()

@client.event
async def on_message_join(member):
    channel = client.get_channel(channel_id)
    embed=discord.Embed(title=f"Welcome {member.name}", description=f"Thanks for joining {member.guild.name}!") # F-Strings!
    embed.set_thumbnail(url=member.avatar_url) # Set the embed's thumbnail to the member's avatar image!

    await channel.send(embed=embed)



์ด์ œ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๊ณ  alt ๊ณ„์ •์„ ๊ฐ€์ ธ์˜ค๊ฑฐ๋‚˜ ์นœ๊ตฌ์—๊ฒŒ ์„œ๋ฒ„์— ๊ฐ€์ž…ํ•˜๋„๋ก ์š”์ฒญํ•˜์„ธ์š”.

ํ•˜์ง€๋งŒ ์ž ๊น... ์ž‘๋™ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค!
๊ตฌ์„ฑ์› ์˜๋„๋ฅผ ํ™œ์„ฑํ™”ํ•ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค!

enabled the Privileged Intents in the dashboard์„(๋ฅผ) ์ˆ˜ํ–‰ํ•œ ํ›„ ์ฝ”๋“œ์—์„œ ํ™œ์„ฑํ™”ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค!

import discord

intents = discord.Intents.default()
intents.members=True
client = discord.Client(intents=intents)

@client.event
async def on_message_join(member):
    channel = client.get_channel(channel_id)
    embed=discord.Embed(title=f"Welcome {member.name}", description=f"Thanks for joining {member.guild.name}!") # F-Strings!
    embed.set_thumbnail(url=member.avatar_url) # Set the embed's thumbnail to the member's avatar image!
    await channel.send(embed=embed)


๋ฐฉ๊ธˆ ์ˆ˜ํ–‰ํ•œ ์ž‘์—…์€ discord.Client๊ฐ€ ์‹œ์ž‘๋  ๋•Œ Members ์˜๋„๋ฅผ ์š”์ฒญํ•˜๋ผ๋Š” ์ง€์‹œ๋ฅผ ๋ฐ›์•˜์Šต๋‹ˆ๋‹ค. ์ด์ œ ํšŒ์› ์ด๋ฒคํŠธ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด์ œ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ๋ด‡์ด ์‚ฌ์šฉ์ž๋ฅผ ํ™˜์˜ํ•˜๋Š”์ง€ ํ™•์ธํ•˜์„ธ์š”!


์งˆ๋ฌธ์ด ์žˆ์œผ์‹ญ๋‹ˆ๊นŒ? ๋‹ค์Œ ๊ฒŒ์‹œ๋ฌผ์— ๋Œ€ํ•ด ์ˆ˜ํ–‰ํ•  ์ž‘์—…์— ๋Œ€ํ•œ ์ œ์•ˆ์ด ์žˆ์Šต๋‹ˆ๊นŒ?



๋Œ“๊ธ€๋กœ ์•Œ๋ ค์ฃผ์‹œ๋ฉด ์ตœ๋Œ€ํ•œ ๋นจ๋ฆฌ ๋‹ต๋ณ€๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค!


์ด ๋‚ด์šฉ์ด ์œ ์šฉํ–ˆ๋‹ค๋ฉด ๊ฒŒ์‹œ๋ฌผ์— ์ข‹์•„์š”๋ฅผ ๋ˆ„๋ฅด๊ณ  ์นœ๊ตฌ์™€ ๊ณต์œ ํ•˜์„ธ์š”! ๋˜ํ•œ ์ €๋ฅผ ํŒ”๋กœ์šฐํ•˜์—ฌ ๋‚ด ์ฝ˜ํ…์ธ ๊ฐ€ ์ถœ์‹œ๋˜์ž๋งˆ์ž ํ”ผ๋“œ์— ์˜ฌ๋ฆด ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ