首页 文章

使用Python Discord bot删除消息?

提问于
浏览
0

我正在尝试制作一个Python Discord Bot,它首先可以删除 Channels 内的消息 . 我希望它是终结者3主题所以它会由用户说天网然后机器人要求激活Y或N?当用户输入Y时,如果用户键入N,它将删除 Channels 中的所有消息,它会说判断日是不可避免的 . 任何帮助将不胜感激 .

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
    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()
    

    这是删除邮件的命令

相关问题