python - twitchio 如何使 Twitch Bot 命令仅对管理员可用?
问题描述
如何使 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()
解决方案
扩展您的代码以支持读取 IRCv3 标签。
您需要启用标签功能
发送
上限要求:twitch.tv/tags
在加入任何房间之前
然后读取badges
a 的标签PRIVMSG
并查找IRCv3 标签的键中存在的broadcaster
ormoderator
徽章badges
例如:
@badge-info=;badges=moderator/1,ambassador/1;client-nonce=ba9231972a6341b6370876a2eb159723;color=#033700;display-name=BarryCarlyon;emotes=;flags=;id=a69c4d4d-541f-4615-89e9-ba278580a2eb ;mod=1;room-id=56410307;subscriber=0;tmi-sent-ts=1614265271314;turbo=0;user-id=15185913;user-type=mod :barrycarlyon!barrycarlyon@barrycarlyon.tmi.twitch.tv PRIVMSG #somechannel :test
你可以看到我有moderator
和ambassador
徽章。
推荐阅读
- hana - 使用 SAP Hana 历史表时出现问题
- python - Django:http客户端的“可读”500页面?
- jquery - 如何在表格的每条记录中的按钮周围设置超链接的属性
- python-3.x - 从本地目录安装 Python 包
- java - Aspect 不适用于某些方法的注释
- java - 如何获取单个谷歌重复事件的 Liferay 日历 SyncEntryId?
- android - 如何在 constraint.Group 中设置涟漪 (android:foreground="?selectableItemBackground")
- kotlin - Kotlin 逃避正斜线使用 Gson
- oracle - istener 目前不知道连接描述符中请求的服务
- powershell - PowerShell 并排问题 EventID 59