首页 > 解决方案 > TwitchIO:删除频道中的单个消息

问题描述

如何删除用户使用 TwitchIO 发送的单条消息?

@bot.event
async def event_message(ctx):
    await ctx.content.delete() # Does not work
    await ctx.content.remove() # Does not work
    await ctx.channel.timeout(ctx.author, 1) # Does not work

标签: python-3.xtwitch-api

解决方案


这个问题比较老,但无论如何我都会回答。
Twitchio 不直接支持这一点。
但是您可以在 Twitch Chat 中删除个别消息,请参阅 Twitch IRC 文档。
CLEARMSG(Twitch 命令)
为此您需要消息 ID。您会在消息标签中获得 ID。
消息标签
代码示例:

async def event_message(message):
    if not message.author.name == self.bot.nick:
        message_id = message.tags['id']
        await message.channel.send(f"/delete {message_id}")

如果要让某人超时,请执行以下操作:

await message.channel.timeout(message.author.name, 120, f"reason")

Twitchio 文档Channel.timeout


推荐阅读