Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. @bot.event
  2. async def on_message(message):
  3. if message.author == bot.user: return
  4. author = message.author
  5. content = message.content
  6. channel = message.channel
  7. if "!add" in content:
  8. content = str(content)
  9. url = content.strip("!add")
  10. url = url.replace(" ", "")
  11. botmessage = "Added URL: " + url
  12. with open("products.txt", "a") as txtfile:
  13. txtfile.write(url+"\n")
  14. print(botmessage)
  15. await message.channel.send(botmessage)
  16. elif "!remove" in content:
  17. content = str(content)
  18. print(content)
  19. urls = content.split(" ")
  20. url = urls[1]
  21. print(url)
  22. txtfile = open("products.txt", "r")
  23. url_links = txtfile.readlines()
  24. txtfile.close()
  25. with open("products.txt", "w") as txt:
  26. for link in url_links:
  27. if url != link:
  28. txt.write(link)
  29. else:
  30. print("found it")
  31. botmessage = "Removed URL: " + url
  32. print("remove")
  33. await message.channel.send(botmessage)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement