업무자동화

discord용 챗봇을 구축해보자!(3)

JackSmith 2023. 5. 7.

이번 시간에는 챗봇을 통해 간단한 명령어들을 입력하여 적절하게 동작시켜보도록 하겠습니다.

 

 

1.요청자를 언급하고 인사하기

 

 

2.명령어에 대해서 별칭지정하기

 

3.요청자로부터 입력받은 문자열을 그대로 반환하기

 

 

4.입력받은 문자열을 공백을 나눠서 반환하기

 

 

전체코드>

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix='$',intents=discord.Intents.all()) #명령어의 시작이 $이다. 예를 들어 -> $안녕

@bot.event
async  def on_ready():
    print(f'{bot.user.name}이 연결 되었습니다.')
    await bot.change_presence(status=discord.Status.online, activity=None)

@bot.command(aliases=['hello','인사'])
async def 안녕(ctx):
    await ctx.send("{} 안녕! 반가워! 잘 지냈니?".format(ctx.author.mention))

@bot.command()
async def 날따라해봐(ctx, *, text):
    await ctx.send(text)

@bot.command()
async def 공백나눠서따라해봐(ctx, *args):
    await ctx.send(args)


bot.run("MTEwNDY3NTU5ODY2OTk3OTY2OA.GrF4uW.-YpUg-Bf7SnzaocAsLasFtVdMxYSuFX4KjnQLI")

참고 및 출처:

https://soopeach.tistory.com/142

 

디스코드 봇 실행 및 간단한 명령어추가(Python-파이썬)

디스코드 봇 만들기 디스코드 봇 만들기 예~전에 디스코드 봇을 만들어보려고 했었을 땐 파이썬으로 만드는 봇은 지원종료가 된다고 했었는데 최근에 확인해보니까 지원 재개를 시작하더라구

soopeach.tistory.com

 

'업무자동화' 카테고리의 다른 글

discord용 챗봇을 구축해보자!(2)  (0) 2023.05.07
discord용 챗봇을 구축해보자!(1)  (0) 2023.05.07

댓글