使用Python Discord bot删除消息?

时间:2018-09-15 19:30:10

标签: python bots discord discord.py

我正在尝试制作一个Python Discord Bot,该机器人首先可以删除通道内的消息。我希望它成为终结者3的主题,这样它就可以由用户说“天网”开始,然后机器人要求激活Y或N?当用户键入Y时,它将删除该频道中的所有消息;如果用户键入N,则将表明判决日是不可避免的。任何帮助将不胜感激。

import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio

token = 'Token'

Client = discord.Client()
client = commands.Bot(command_prefix = '!')


@client.event
  async def on_ready():
     print("Skynet Online")

@client.event

  async def on_message(message):
    if message.content == 'skynet':
        await client.send_message(message.channel, 'Execute Y/N?')

@asyncio.coroutine
  async def delete_messages(messages):
    if message.content == 'Y':
        await client.delete_messages()


client.run('Token')

1 个答案:

答案 0 :(得分:0)

import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio

@has_permissions(manage_messages=True, read_message_history=True)
@bot_has_permissions(manage_messages=True, read_message_history=True)
async def purge(ctx, limit: int = 100, user: d.Member = None, *, matches: str = None):
    """Purge all messages, optionally from ``user``
    or contains ``matches``."""
    logger.info('purge', extra={'ctx': ctx})
    def check_msg(msg):
        if msg.id == ctx.message.id:
            return True
        if user is not None:
            if msg.author.id != user.id:
                return False
        if matches is not None:
            if matches not in msg.content:
                return False
        return True
    deleted = await ctx.channel.purge(limit=limit, check=check_msg)
    msg = await ctx.send(i18n(ctx, 'purge', len(deleted)))
    await a.sleep(2)
    await msg.delete()

这是删除邮件的命令