File "main.py", line 55, in on_message
options = options + db['encouragements']
TypeError: can only concatenate list (not "ObservedList") to list
how to fix it
File "main.py", line 55, in on_message
options = options + db['encouragements']
TypeError: can only concatenate list (not "ObservedList") to list
how to fix it
Please post your code if you need coding help, otherwise it’s impossible to help you
this problem have be fix, i see in this web and find how to fix it
i type $inspire my bot reply <function get_quote at 0x7f14502065e0>
and i type $del 0 ObservedList(value=[’ you are amazing too’])
Please give more infos, and share your code
i have one more quest
im use command $responding false why my bot no say anythings.
console don’t have error
this is the code
import os
import discord
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!'
]
if 'responding' not in db.keys():
db['responding'] = True
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']
return(quote)
def update_encouragements(encouraging_message):
if 'encouragements' in db.keys():
encouragements = db['encouragements']
encouragements.append(encouraging_message)
db['encouragements'] = encouragements
else:
db['encouragements'] = [encouraging_message]
def delete_encouragement(index):
encouragements = db['encouragements']
if len(encouragements) > index:
del encouragements[index]
db['encouragements'] = encouragements
@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
msg = message.content
if msg.startswith('$inspire'):
quote = get_quote
await message.channel.send(quote)
if db['responding']:
options = starter_encouragements
if 'encouragements' in db.keys():
options = options.extend(db['encouragements'])
if any(word in msg for word in sad_words):
await message.channel.send(random.choice(starter_encouragements))
if msg.startswith('$new'):
encouraging_message = msg.split('$new',1)[1]
update_encouragements(encouraging_message)
await message.channel.send('New encouraging ,essage added')
if msg.startswith('$del'):
encouragements = []
if 'encouragements' in db.keys():
index = int(msg.split('$del',1)[1])
delete_encouragement(index)
encouragements = db['encouragements']
await message.channel.send(encouragements)
if msg.startswith('$list'):
encouragements = []
if 'encouragements' in db.keys():
encouragements = db['encouragements']
await message.channel.send(encouragements)
if msg.startswith('$responding'):
value = msg.split('$responding ',1)[1]
if value.lower() == 'true':
db['responding'] = True
await message.channel.send('Responding is on.')
else:
db['responding'] = False
await message.channel.send('Responding is off.')
client.run(os.getenv('TOKEN'))
import os
import discord
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!'
]
if 'responding' not in db.keys():
db('responding') = True
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']
return(quote)
def update_encouragements(encouraging_message):
if 'encouragements' in db.keys():
encouragements = db['encouragements']
encouragements.append(encouraging_message)
db['encouragements'] = encouragements
else:
db['encouragements'] = [encouraging_message]
def delete_encouragement(index):
encouragements = db['encouragements']
if len(encouragements) > index:
del encouragements[index]
db['encouragements'] = encouragements
@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
msg = message.content
if msg.startswith('$inspire'):
quote = get_quote
await message.channel.send(quote)
if db('responding'):
options = starter_encouragements
if 'encouragements' in db.keys():
options = options.extend(db['encouragements'])
if any(word in msg for word in sad_words):
await message.channel.send(random.choice(starter_encouragements))
if msg.startswith('$new'):
encouraging_message = msg.split('$new',1)[1]
update_encouragements(encouraging_message)
await message.channel.send('New encouraging ,essage added')
if msg.startswith('$del'):
encouragements = []
if 'encouragements' in db.keys():
index = int(msg.split('$del',1)[1])
delete_encouragement(index)
encouragements = db['encouragements']
await message.channel.send(encouragements)
if msg.startswith('$list'):
encouragements = []
if 'encouragements' in db.keys():
encouragements = db['encouragements']
await message.channel.send(encouragements)
if msg.startswith('$responding'):
value = msg.split('$responding',1)[1]
if value.lower() == 'true':
db['responding'] = True
await message.channel.send('Responding is on')
else:
db['responding'] = False
await message.channel.send('Responding is off')
client.run(os.getenv('TOKEN'))
import os
import discord
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!'
]
if 'responding' not in db.keys():
db['responding'] = True
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']
return(quote)
def update_encouragements(encouraging_message):
if 'encouragements' in db.keys():
encouragements = db['encouragements']
encouragements.append(encouraging_message)
db['encouragements'] = encouragements
else:
db['encouragements'] = [encouraging_message]
def delete_encouragement(index):
encouragements = db['encouragements']
if len(encouragements) > index:
del encouragements[index]
db['encouragements'] = encouragements
@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
msg = message.content
if msg.startswith('$inspire'):
quote = get_quote
await message.channel.send(quote)
if db['responding']:
options = starter_encouragements
if 'encouragements' in db.keys():
options = options.extend(db['encouragements'])
if any(word in msg for word in sad_words):
await message.channel.send(random.choice(starter_encouragements))
if msg.startswith('$new'):
encouraging_message = msg.split('$new',1)[1]
update_encouragements(encouraging_message)
await message.channel.send('New encouraging ,essage added')
if msg.startswith('$del'):
encouragements = []
if 'encouragements' in db.keys():
index = int(msg.split('$del',1)[1])
delete_encouragement(index)
encouragements = db['encouragements']
await message.channel.send(encouragements)
if msg.startswith('$list'):
encouragements = []
if 'encouragements' in db.keys():
encouragements = db['encouragements']
await message.channel.send(encouragements)
if msg.startswith('$responding'):
value = msg.split('$responding ',1)[1]
if value.lower() == 'true':
db['responding'] = True
await message.channel.send('Responding is on.')
else:
db['responding'] = False
await message.channel.send('Responding is off.')
client.run(os.getenv('TOKEN'))
Please wait for your post to be approved, do not create many posts
I have merged your topics
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).
It doesn’t answer because it’s inside the other if statement, make sure to use the correct indentation for your code, otherwise you get the wrong logic flow
thank you for help, i fix it
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.