파이썬으로 디스코드 서버에 챗봇 붙이는 프로젝트 진행
1. 디스코드 서버 열기
2. 파이썬에 디스코드 설치
pip install discord
3. import 디스코드
4. 디스코드 개발자 채널에 가서, bot 키 생성
https://discord.com/developers/applications
생성하는 방법은 여기에->https://scvtwo.tistory.com/196
5. 파이썬에서 아래와 같이 명령문 코딩
import discord
from discord.ext import commands
DISCORD_BOT_KEY = '디스코드 봇 키 입력'
# Intents 객체 생성
intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)
bot = commands.Bot(command_prefix=';',intents=discord.Intents.all())
@bot.event
async def on_ready():
print("봇이 시작되었습니다.")
@bot.command()
async def 안녕(ctx):
await ctx.send('안녕하세요!')
@bot.command()
async def 바보(ctx):
await ctx.send("{}라고 하셨군요, 반갑습니다 바보똥꼬 {}님!".format(
ctx.message.content, ctx.author.name))
@bot.command()
async def 추방(ctx):
if ctx.message.content.startswith(";추방"):
member = ctx.message.guild.get_member(int(ctx.message.content.split(" ")[1]))
await ctx.message.guild.kick(member, reason=None)
bot.run('디스코드 봇 키 입력')
'파이썬 수업 > 파이썬 미니프로젝트' 카테고리의 다른 글
[파이썬] 행맨(hang man) (0) | 2023.10.21 |
---|---|
[파이썬] 테트리스 만들기 (0) | 2023.10.21 |
[파이썬] 파이썬 파일을 exe파일로 출력하기 - pyinstaller (0) | 2023.06.10 |
[파이썬 프로젝트] tkinter로 실행파일 만들기 (0) | 2023.05.06 |
[파이썬] 지렁이게임 만들기 - pygame (0) | 2023.04.22 |
Comment