Discord bot literal for int () with base 10 problem

I was making a discord bot with the help of this video. My other code runs well but whenever I del a encouragement I face the problem. The problem shows in this index = int(msg.split("$del",1)[1]) line. The console tells me that there’s a literal for int() with base 10 problem. And there for I can’t delete and encouragements. But I can add them or do other things. Here’s the code I went so far:

import discord
import os
import requests
import json
import random
from replit import db

client = discord.Client()

sad_words = ["sad", "depressed", "unhappy", "angry", "miserable", "depressing"]

starter_encouragements = [
  "Cheer up!",
  "Hang in there.",
  "You are a great person / bot!"

def get_quote():
  response = requests.get("https://zenquotes.io/api/random")
  json_data = json.loads(response.text)
  quote = json_data[0]['q'] + " -" + json_data[0]['a']

def update_encouragements(encouraging_message):
  if "encouragements" in db.keys():
    encouragements = db["encouragements"]
    db["encouragements"] = encouragements
    db["encouragements"] = [encouraging_message]

def delete_encouragment(index):
  encouragements = db["encouragements"]
  if len(encouragements) > index:
    del encouragements[index]
    db["encouragements"] = encouragements

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

async def on_message(message):
  if message.author == client.user:

  msg = message.content

  if msg.startswith('$inspire'):
    quote = get_quote()
    await message.channel.send(quote)

  options = starter_encouragements
  if "encouragements" in db.keys():

  if any(word in msg for word in sad_words):
    await message.channel.send(random.choice(options))

  if msg.startswith("$new"):
    encouraging_message = msg.split("$new ",1)[1]
    await message.channel.send("New encouraging message added.")

  if msg.startswith("$del"):
    encouragements = []
    if "encouragements" in db.keys():
      index = int(msg.split("$del",1)[1])
      encouragements = db["encouragements"]
    await message.channel.send(encouragements)


what problem are you facing? what error are you getting?

Literal for int() with base 10 in the line int(msg.split("$del",1)[1])
And for that I am unable to delete any encouragements.

Your problem is literally what It says. You’re getting a string inside int(). Basically, when you type the command in your server "$del 0’, for example, this command intends to delete the “$del” and the space after It. The only thing I can think is that you’re typing the messages wrong.

I didn’t get you properly but my command was $del Way to go. for example. It should delete the Way to go. and space before that, right?

Well, I was right, you’re using the commands wrong. Your phrases are stored inside a list like, [‘Way To Go’, ‘You are the best’, ‘Hang in there’]. Each item is accessed by a number, like, in this list I just typed ‘Way To Go’ is in the position 0, ‘You are the best’ is in the position 1 and ‘Hang in there’ is in the position 2. If I want to delete ‘You are the best’ for example, I would have to type “$del 1”.

1 Like

if msg.startswith("$del"):
encouragements = [ ]
if “encouragements” in db.keys():
index = db[“encouragements”].index(msg.split(’$del’, 1)[1].strip())
encouragements = db[“encouragements”]
await message.channel.send(encouragements)

Try this. It might make It work the way you want to.

Basically, this changes the way It works. Instead of type ‘$del number’, you can type in the way you were doing, “$del phrase” (ex: “$del Way To Go”). Not sure if It’s going to work though, just testing to know.

It’s working now. Thank you very much. Take many many love.

1 Like

You’re welcome! If you find any other problem, I’ll be glad to help again.

1 Like

I think I’ll face more problem. I am building the bot as a beginner. It will be fine if I have someone professional as you.

1 Like

Don’t worry, you probably will be fine if you follow the video, you just have to check every line. The thing is, if you miss even a character in your code or type the wrong commands, the program will break, so you have to recheck everything as much as possible.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.