twitchio 如何让 Twitch Bot 命令仅对管理员可用?

时间:2021-02-23 04:03:42

标签: python python-3.x twitch twitch-api

如何让 Twitch Bot 命令仅供管理员使用? 有些命令只有管理员可以使用,有些命令是所有人都可以使用的。

这是我的代码:

from twitchio.ext import commands
import openpyxl
from openpyxl import load_workbook
from decouple import config

temp_initial_channels = str(config('CHANNEL'))
temp_xlsx_name = str(config('XLSX_NAME'))

class Bot(commands.Bot):
    def __init__(self):
        super().__init__(irc_token=config('TMI_TOKEN'), client_id=config('CLIENT_ID'), nick=config('BOT_NICK'), prefix=config('BOT_PREFIX'),
                         initial_channels=[temp_initial_channels])

    async def event_ready(self):
        ws = bot._ws
        await ws.send_privmsg("whitebot201", f"whitebot201 이 준비 완료 되었습니다!")

    async def event_message(self, message):
        print(message.content)
        await self.handle_commands(message)
    
    @commands.command(name='test')
    async def test(self, ctx):
        await ctx.send(f'test pass!!!')


bot = Bot()
bot.run()

1 个答案:

答案 0 :(得分:0)

扩展您的代码以支持读取 IRCv3 标签。

您需要启用标签功能

发送

<块引用>

CAP REQ :twitch.tv/tags

在加入任何房间之前

然后读取 badges 标签的 PRIVMSG 并查找 IRCv3 标签的 broadcaster 键中存在的 moderatorbadges 徽章

例如:

<块引用>

@badge-info=;badges=moderator/1,ambassador/1;client-nonce=ba9231972a6341b6370876a2eb159723;color=#033700;display-name=BarryCarlyon;emotes=;flags=;id=a665c45 89e9-ba278580a2eb;mod=1;room-id=56410307;subscriber=0;tmi-sent-ts=1614265271314;turbo=0;user-id=15185913;user-type=mod :barrycarlyon@!barrycarlyont twitch.tv PRIVMSG #somechannel :test

你可以看到我有 moderatorambassador 徽章。