''Ignoring exception in on_message' discord.py ignoring if statement
I have this code in my discord bot using discord.py
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.author not in config.sections() and message.content == '!!acc': #it seems to ignore this if statement and simply tries executing the code below
config.add_section(str(message.author))
config.set(str(message.author), 'Enemy', '10')
config.set(str(message.author), 'Money', '0')
config.set(str(message.author), 'Damage', '1')
config.set(str(message.author), 'Level', '1')
response = "Your Profile has been created, these are your stats: \nCurrent money: 0 \nCurrent Damage: 1 \nCurrent level: 1"
elif message.content == '!!acc': #this is getting completely ignored too
response = "Current money: "+str(config.get(message.author, 'Money'))+ "\nCurrent Damage " +str(config.get(message.author, 'Damage'))+ "\nCurrent level: "+str(config.get(message.author, 'Level'))
but whenever i type the command !!acc while already heaving an entry in the config i get the following error
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "D:\coding\bot\gamebot.py", line 29, in on_message
config.add_section(str(message.author))
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\configparser.py", line 1212, in add_section
super().add_section(section)
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\configparser.py", line 659, in add_section
raise DuplicateSectionError(section)
configparser.DuplicateSectionError: Section 'discord-name' already exists
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
