1

I want to send a message which uses the message content
If a user writes !alcool, for example, I want my bot to answer textealcool.png

If they write !car, I want textecar.png.

My code is :

from discord.ext.commands import Bot

BOT_PREFIX = ("!")
TOKEN = "XXXXXX"

client = Bot(command_prefix=BOT_PREFIX)

@client.event
async def on_message(message):
    if message.content.startswith("!"):
        newMessage = 'texte' + str(message.content)[1:] + '.png'
        await client.send_message(message.channel, newMessage)

client.run(TOKEN)

I wrote "!alcool" but my Bot answered with :

textealcool
texte!alcool
textealcool
texte
textealcool.pgn
textealcool.pgn
textealcool
textealcool.pgn
textealcool

I don't understand why I have so many answers with only two are right.

user10849497
  • 25
  • 1
  • 4
  • The reason you might be seeing more outputs is that you have multiple instances running at the same time on the same token – Tristo Dec 30 '18 at 16:57

1 Answers1

0

In the line
newMessage = 'texte' + str(messagelu)[1:] + '.png' what is messagelu?
Change messagelu to message.content and it will work

Tristo
  • 2,328
  • 4
  • 17
  • 28
  • messagelu=message.content / message.content was the code from the start but i tried to use reference after that. => it doesn't work with message.content :( – user10849497 Dec 30 '18 at 17:34
  • It should, are you sure you're not running the old code versions simultaneously? – Tristo Dec 30 '18 at 18:03
  • It's possible. I don't really understand how the discord bot is linked to my program. thanks. – user10849497 Dec 30 '18 at 18:15
  • I am pretty sure now it's due to my bot running old version of my programm in the same time. I tried to change my programm to send a link to a picture and only one echoes show the link to the picture. Do you know how I can avoid that please ? Thanks. – user10849497 Dec 30 '18 at 19:20
  • I solved my problem by doing ctrl+alt+suppr and kill all python runing in windows 10. But does it mean my bot won't do anything if I turn off my pc ? – user10849497 Dec 30 '18 at 20:04
  • Unless you host it somewhere like heroku when you shut down your pc it will turn off – Tristo Dec 30 '18 at 20:28
  • I thank you a lot Tristo. I create a gitHub and Heroku account but I am stuck with another problem (ModuleNotFoundError: No module named 'discord') but it's not the topic here. – user10849497 Jan 01 '19 at 12:09
  • Check out [this](https://stackoverflow.com/questions/52247301/how-do-i-host-my-discord-py-bot-on-heroku/52254616#52254616) checklist I created a while back – Tristo Jan 01 '19 at 12:14
  • It sounds like you need to update [your procfile](https://stackoverflow.com/a/51914768/9917504) – Tristo Jan 01 '19 at 13:54
  • I am working on it and I am stuck again. I tried to add each of these items and nothing work : discord.py==3.6.7 || git+https://github.com/Rapptz/discord.py@rewrite#egg=discord.py[voice] || discord || discord.py – user10849497 Jan 01 '19 at 14:01
  • I don't know what the problem could be and the comment formatting is often very limited, try making a new post explaining the issue – Tristo Jan 01 '19 at 15:15
  • 1
    The problem came from spelling requirement.txt instead of requirements.txt...doh ! – user10849497 Jan 01 '19 at 23:21