【问题标题】:Discord.py - Deleting messages in a channel that do not start with a specific wordDiscord.py - 删除频道中不以特定单词开头的消息
【发布时间】:2021-08-10 08:16:05
【问题描述】:

是否有可能使在特定频道中,任何时候有人键入不以特定单词或短语开头的消息时都会被删除?

【问题讨论】:

标签: python python-3.x discord.py


【解决方案1】:

你可以这样做:

import discord

client = discord.Client()

@client.event
async def on_message(message):
    if message.channel.id == your_id:
        if not message.content.startswith("your_word"):
            await message.delete()

【讨论】:

  • 请注意,如果他使用会破坏脚本中所有命令的机器人类,则可以通过discordpy.readthedocs.io/en/latest/… 轻松修复
  • @Rémy Noulin 出于某种原因,它说“消息”对象没有属性“startswith”。你知道我怎么能解决这个问题吗,因为我到处搜索却找不到任何东西?
  • 我的错,是message.content.startswith("your_word") 会在主信息中解决这个问题,抱歉,我没注意
猜你喜欢
  • 1970-01-01
  • 2021-08-17
  • 2019-06-13
  • 1970-01-01
  • 2020-09-23
  • 2022-01-12
  • 2020-10-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多