【发布时间】:2020-09-13 18:56:15
【问题描述】:
我想使用 discord.py 删除来自特定用户的特定消息 用户id为:462616472754323457 他无法发送的消息:lmao 因此,如果他发送 lmao,它会删除消息并发送“你不能这样做
【问题讨论】:
标签: discord message discord.py
我想使用 discord.py 删除来自特定用户的特定消息 用户id为:462616472754323457 他无法发送的消息:lmao 因此,如果他发送 lmao,它会删除消息并发送“你不能这样做
【问题讨论】:
标签: discord message discord.py
@client.event
async def on_message(message):
if len(await message.channel.purge(limit=200, check=lambda x: ('lmao' in x.content.strip().lower()) and x.author.id == 462616572754323457)) > 0:
await message.channel.send('You are not allowed to do that, <@462616572754323457>')
当机器人离线时,机器人将检查当前消息之前的 200 条消息,并删除来自462616572754323457 并且内容中有'lmao' 的任何消息。 (您可以使用re 进一步增强此功能。)
【讨论】:
x.author.id == 462616572754323457 更改为 True。
您可以使用on_message 事件,该事件在发送消息时触发。
@bot.event
async def on_message(message):
await bot.process_commands(message) # add this if also using command decorators
if message.author.id == 462616472754323457 and "lmao" in message.content.lower():
await message.delete()
await message.channel.send(f"You can't do that, {message.author.mention}")
参考资料:
【讨论】: