1
votes

I'm trying to make a Python Discord Bot that firstly can delete messages within a channel. I wanted it to be Terminator 3 themed so it would start out by the user saying Skynet then the bot asks to activate Y or N? and when the user types Y it would delete all the messages in the channel if the user typed N it would say judgment day is inevitable. any help would be greatly appreciated.

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
What is the exact problem that is occuring? You never asked a specific question for people to answer.Karl
the message content or response 'Y' doesn't trigger the bot to delete messages. However, the first message when typing skynet does make the bot output the Y or N?Fausto Rodriguez
There are already a few questions around about using Client.wait_for_message to have interactive commands.Patrick Haugh

1 Answers

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

That is the command to delete messages