iT邦幫忙

2021 iThome 鐵人賽

DAY 16
1
AI & Data

建立FF14資訊Discord chatbot系列 第 16

[DAY 16]用bot打出色色柴犬counter牌

最近很夯的色色柴犬大家應該有聽過吧

沒錯就是這一系列牌組

然後某一天晚上不知道我發什麼神經突然有個念頭想寫個別人留言"可以色色"、"不可以色色"時拿對應的牌去康特他的想法

然後回過神來時發現頻道上已經出現下面畫面

實現原理很簡單,目前的牌組發動條件主要有三種

  1. 可以色色
  2. 不可以色色
  3. 複數條件

前兩種用一般的判斷式寫就可以了,每個判斷裡面我有放該種類圖檔的list隨機抽取一張

第三種的發動條件像色色武士要"可以色色"跟"不可以色色"同時在場才會出現

這種類型的牌要另外處理

所以我有在程式碼加個table list

當留言出現"可以色色"跟"不可以色色"出現時會把這兩個字串加進table list裡面

發動過後檯面上的牌全部清掉

這邊舉個範例

現在想想那天我一定是喝多了才會做出這鬼東西

附上用cog架構寫的程式碼,cog架構可參考我之前寫的文章

import pandas as pd
from discord.ext import commands
from core.classes import Cog_Extension
import discord
from random import choice

class main(Cog_Extension):
    def __init__(self,*args,**kwargs):
        super().__init__(*args,**kwargs)
        self.table=[]
        self.nohokh = ["https://i.imgur.com/cZksr04.jpg","https://i.imgur.com/wH4CJLF.jpg","https://i.imgur.com/ag0DVMT.jpg"]
    @commands.Cog.listener()
    #當有訊息時
    async def on_message(self,message):
        embed = discord.Embed()
        #排除自己的訊息,避免陷入無限循環
        if message.author == self.bot.user:
            return
        
        
        #不可以色色排組對應圖片
        if message.content.startswith("不可以色色"):
            if "可以色色" and "不可以色色" in self.table:
                self.table=[]
                await message.reply(choice(self.nohokh))#特招
            else:
                noh = ["https://imgur.dcard.tw/TUGMyF7h.jpg","https://imgur.dcard.tw/ZayW5My.jpg","https://i.imgur.com/WLbQBlT.jpg","https://i.imgur.com/nGI4pbO.jpg","https://i.imgur.com/jrOvlgH.jpg","https://i.imgur.com/68mqoce.jpg"]
                self.table.append("不可以色色")
                await message.reply(choice(noh))#不可以色色康特
            # await message.channel.send(embed=embed)
        elif message.content.startswith("可以色色"):
            if "可以色色" and "不可以色色" in self.table:
                self.table=[]
                await message.reply(choice(self.nohokh))#特招
            else:
                okh = ["https://i.imgur.com/UVZti2m.jpg","https://i.imgur.com/FoGDvP7.jpg","https://i.imgur.com/c2pDzLJ.jpg","https://i.imgur.com/0Ux7atA.jpg","https://i.imgur.com/hnnSpzr.jpg","https://i.imgur.com/F03Raad.jpg"]
                self.table.append("可以色色")
                await message.reply(choice(okh))#可以色色康特
        


def setup(bot):
    bot.add_cog(main(bot))

上一篇
[DAY 15]cog架構用法(2/2)
下一篇
[DAY 17]Discord server串接webhook
系列文
建立FF14資訊Discord chatbot30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言