놀아보자/파이썬기초

Discord 챗봇 view_3/3

nolja 2022. 8. 9. 21:15

import discord
from discord.ui import Button, View
from discord.ext import commands

intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix=">", intents=intents)
Interaction : discord.Interaction = discord.Interaction

class MusicView(View):
    @discord.ui.button(label = "애국가", style = discord.ButtonStyle.green, emoji="✌")
    async def button_1_callback(self, button, Interaction):
        await Interaction.response.edit_message(view = NationalAnthemView())
    
    @discord.ui.button(label = "동요", style = discord.ButtonStyle.green, emoji="✌")
    async def button_2_callback(self, button, Interaction):
        await Interaction.response.edit_message(view = ChildrenSongView())

class NationalAnthemView(View):
    @discord.ui.button(label = "애국가 1절", style = discord.ButtonStyle.green, emoji="✌")
    async def button_1_callback(self, button, Interaction):
        await Interaction.response.send_message(
"""동해 물과 백두산이 마르고 닳도록
하느님이 보우하사 우리나라 만세.
무궁화 삼천리 화려 강산
대한 사람, 대한으로 길이 보전하세.""")
    @discord.ui.button(label= "애국가 2절", style= discord.ButtonStyle.secondary)
    async def button_2_callback(self, button, Interaction):
        await Interaction.response.send_message(
"""남산 위에 저 소나무, 철갑을 두른 듯
바람 서리 불변함은 우리 기상일세.
무궁화 삼천리 화려 강산
대한 사람, 대한으로 길이 보전하세.""")
    
    @discord.ui.button(label= "애국가 3절", style= discord.ButtonStyle.success)
    async def button_3_callback(self, button, Interaction):
        await Interaction.response.send_message(
"""가을 하늘 공활한데 높고 구름 없이
밝은 달은 우리 가슴 일편단심일세.
무궁화 삼천리 화려 강산
대한 사람, 대한으로 길이 보전하세.""")
    
    @discord.ui.button(label= "애국가 4절", style= discord.ButtonStyle.danger)
    async def button_4_callback(self, button, Interaction):
        await Interaction.response.send_message(
"""이 기상과 이 맘으로 충성을 다하여
괴로우나 즐거우나 나라 사랑하세.
무궁화 삼천리 화려 강산
대한 사람, 대한으로 길이 보전하세.""")

class ChildrenSongView(View):
    @discord.ui.button(label = "곰세마리", style = discord.ButtonStyle.green, emoji= "🤗")
    async def button_1_callback(self, button, Interaction):
        await Interaction.response.send_message(
"""곰 세 마리가 한 집에 있어
아빠 곰 엄마 곰 애기 곰
아빠 곰은 뚱뚱해
엄마 곰은 날씬해
애기 곰은 너무 귀여워
으쓱 으쓱 잘한다""")

@bot.command()
async def 노래(ctx):
    view = MusicView()
    await ctx.send("선택하세요.", view=view)

bot.run('자신의 토큰')

'놀아보자 > 파이썬기초' 카테고리의 다른 글

SmartFactory basic  (1) 2023.11.30
Discord 챗봇 view_2/3  (0) 2022.08.09
Discord 챗봇 view_1/3  (0) 2022.08.09
Discord 챗봇 동작 테스트  (1) 2022.08.09
turtle 실습  (0) 2022.01.08