Search code examples
pythondiscorddiscord.pychatbot

How can I remove a character from message.content?


I'm currently trying to make my bot say whatever I say. So, the bot gets activated if my message starts with the "§" symbol. It's supposed to delete my message, delete the "§" character out of it, and then post it without that symbol in that same chat.

I've tried a few things, including subtracting the symbol or making it a string, but nothing has worked. So, what can I do?

@client.event
@commands.has_permissions(manage_messages = True)
async def on_message(message):
    if message.content.startswith('§'):
        channel1 = message.channel
        await message.delete()
        await channel1.send(f'{message.content}' - '§')

Here, I get an error message saying:

await channel1.send(f'{message.content}' - '§')
TypeError: unsupported operand type(s) for -: 'str' and 'str'

How can I make it so that the "§" symbol gets deleted from the message?


Solution

  • Replace the prefix with an empty string

    await channel1.send(f"{message.content.replace('§', '')}")