Discord.py Repeat message, delete command

Solution for Discord.py Repeat message, delete command
is Given Below:

I’ve gotten it to repeat the message in total, but how do I have it remove the command prefix, and delete the message?

import discord
import os

client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
        return
  
    if message.content.startswith('.say'):
        await message.channel.send(message.content)

client.run(os.getenv('TOKEN'))

To get rid of the bot sending the command prefix you can use [4:] when sending so the first four characters are not sent!

And to delete the message of the user you can use the command: await message.delete()

So the complete code would be:

import discord
import os

client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
        return
  
    if message.content.startswith('.say'):
        await message.channel.send(message.content[4:])
    await message.delete()

client.run(os.getenv('TOKEN'))

I would check out the discord.py documentation linked here

I would recommend using discord.ext.commands here is your code made into a commands.Bot instead of discord.client

use .say LONGMESSAGE HERE to invoke the command

import discord
from discord.ext import commands
import os

bot = commands.Bot(command_prefix='.')

@bot.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@bot.command()
async def say(ctx,* , data:str = None):
    if not data:
        return await ctx.send('please enter some data')

    await ctx.message.delete()
    await ctx.send(data)

bot.run(os.getenv('TOKEN'))

Read more