I’ve changed it a bit and with the adding of new “encouraging words” it’s get nasty and i cant get the mistake in line 63… ( so says the Console, but i know it could be anywhere else too)
import discord
import os
import requests
import json
import random
from replit import db
client = discord.Client()
bad_words = ["arschloch", "hurensohn", "Hurensohn", "Hure", "bastard"]
starter_encouragements = [
"Wir wünschen die Einhaltung der **Netiquette** ansonsten wirst du gebannt!",
"Achtung, mute in 5 Minuten",
"Leb dein Leben du Kek"
]
# 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('Hello'):
await message.channel.send('Hi {user}')
if msg.startswith('Hilfe'):
await message.channel.send('Wenn du Hilfe brauchst, wende dich an einen <@&686472311615914024>')
if msg.startswith('Willkommen'):
await message.channel.send('Welcome Buddy')
options = starter_encouragements
if "encouragements" in db.keys():
options = options + db["encouragements"]
if any(word in msg for word in bad_words):
await message.channel.send(random.choice(options))
if msg.startswith("$new"):
encouraging_message = msg.split("$new ",1)[1]
update_encouragements(encouraging_message)
await message.channel.send("New encourage message 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)
client.run(os.environ['TOKEN'])
i solved the options = options + db[“encouragements”] problem with adding an .value to it. By now, and even if i do it another way with options.extend it will show up the error code i attached here. Maybe you could help me out. This is the code, error in line 29, and 70
import discord
import os
import requests
import json
import random
from replit import db
client = discord.Client()
bad_words = ["arschloch", "hurensohn", "Hurensohn", "Hure", "bastard"]
starter_encouragements = [
"Wir wünschen die Einhaltung der **Netiquette** ansonsten wirst du gebannt!",
"Achtung, mute in 5 Minuten",
"Leb dein Leben du Kek"
]
# 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('Hello'):
await message.channel.send('Hi {user}')
if msg.startswith('Hilfe'):
await message.channel.send('Wenn du Hilfe brauchst, wende dich an einen <@&686472311615914024>')
if msg.startswith('Willkommen'):
await message.channel.send('Welcome Buddy')
options = starter_encouragements
if "encouragements" in db.keys():
options = options + db["encouragements"].value
if any(word in msg for word in bad_words):
await message.channel.send(random.choice(options))
if msg.startswith("$new"):
encouraging_message = msg.split("$new ",1)[1]
update_encouragements(encouraging_message)
await message.channel.send("New encourage message 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)
client.run(os.environ['TOKEN'])
As these two posts are related to the same project, I have combined them to help keep the forum easier to navigate, and keep the conversation on one thread.
Thanks for that Sky020, yes thats because i get rid of one problem and didn’t noticed that my other Thread wasn’t released yet. I’ve edited my Entry because somehow it works better but now it says there is no definition… in the tutorial it worked this way too so the definition is given or am i missing something?
Nevermind the first post ( got the ObservedList Problem solved) , the second one is relevant. I’ve attached the error code. There is a Problem with the definition of encouraging. In Line 29 at encouragements.append(encouraging.message) and in Line 70 with update_encouragements(encouraging_message)
def update_encouragements(encouraging_message): x
if "encouragements" in db.keys():
encouragements = db["encouragements"]
encouragements.append(encouraging_message) x
WORKED. But then new Problem appears, now the next step would be the $del command. Now it says: Invalid literal for int() with base 10 in line 76 sooo it’s here:
if msg.startswith("$del"): 73
encouragements = [] 74
if "encouragements" in db.keys(): 75
index = int(msg.split("$del",1)[1]) 76
delete_encouragement(index) 77
encouragements = db["encouragements"] 78
await message.channel.send(encouragements) 79
Nice pun. I look for them, but they are not really revealing for me.
I’ll add them here i don’t know where to go otherwise.
BTW: The Debugger says everything if fine