Parsing a script in discord.py to display - python-3.x

#bot.command()
async def test(ctx):
with open("C:\\bot\\cn.txt", 'r') as file:
lines = file.readlines()
for line in lines:
values = line.split("|")
for value in values:
dbdc = [dbdc for dbdc in values[2:3] if dbdc == 'DOOMBIRD DOOMCAVE' and list.count[0] < 6]
print(dbdc[0])
Right now, it's displaying the users who don't exceed the value 6, so that works, but it's not filtering it out to match the text.
What I am trying to make it do, is read the txt file, match values**[3]** to the text, ie 'DOOMBIRD DOOMCAVE'. Then, I want it to check [1] to see if it shows up more than 6 times. Finally, once those conditions are met, I want it to print the results. Unfortunately, it pops up with Index out of range.
[error message][1]
text file:
Declaring ID|Declaring Ruler|Declaring Nation|Declaring Alliance|Declaring Alliance ID|Declaring Team|Receiving ID|Receiving Ruler|Receiving Nation|Receiving Alliance|Receiving Alliance ID|Receiving Team|Status|Money|Technology|Soldiers|Date|Reason|Aid ID|
Ignoring exception in command test:
Traceback (most recent call last):
File "C:\Users\justi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "c:\bot\eraserhead.py", line 343, in test
print(dbdc[0])
IndexError: list index out of range
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\justi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\discord\ext\commands\bot.py", line 902, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\justi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\discord\ext\commands\core.py", line 864, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\justi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: IndexError: list index out of range```

Related

Discord bot error handling doesn't allow me to pass 3 arguments

I am unable to pass 3 arguments (self, error, ctx) to my error handler shown bellow every time I try whatever argument I pass last comes back as a missing argument.
#bot.command(name='dice')
async def dice(ctx, number_of_dice: int, number_of_sides: int):
dice = [
str(random.choice(range(1, number_of_sides + 1)))
for x in range(number_of_dice)
]
await ctx.send(', '.join(dice))
#dice.error
async def dice_handler(self, error, ctx):
message = (
'the dice command needs the number of dice and the number of sides'
' to run. \n Example: dice 1 20\n will roll 1 dice with 20 sides')
if isinstance(error, commands.MissingRequiredArgument):
if error.param.name == "number_of_dice":
await ctx.send(message)
elif error.param.name == "number_of_sides":
await ctx.send(message)
this is the output i receive.
Irresistible Bot has connected to discord!
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\kit\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\kit\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 855, in invoke
await self.prepare(ctx)
File "C:\Users\kit\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 789, in prepare
await self._parse_arguments(ctx)
File "C:\Users\kit\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 697, in _parse_arguments
transformed = await self.transform(ctx, param)
File "C:\Users\kit\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 542, in transform
raise MissingRequiredArgument(param)
discord.ext.commands.errors.MissingRequiredArgument: number_of_dice is a required argument that is missing.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\kit\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 71, in wrapped
ret = await coro(*args, **kwargs)
TypeError: dice_handler() missing 1 required positional argument: 'ctx'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\kit\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "C:\Users\kit\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 979, in on_message
await self.process_commands(message)
File "C:\Users\kit\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 976, in process_commands
await self.invoke(ctx)
File "C:\Users\kit\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 943, in invoke
await ctx.command.dispatch_error(ctx, exc)
File "C:\Users\kit\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 424, in dispatch_error
await injected(ctx, error)
File "C:\Users\kit\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 77, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: dice_handler() missing 1 required positional argument: 'ctx'
i figured it out i did not need to use self because I am not using cog.
self parameter is just for cogs. You aren't using cogs so, dice_handler takes only context and error parameters.

TypeError while programming a discord bot

Ignoring exception in on_message
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "main.py", line 162, in on_message
checo_fifa()
File "main.py", line 99, in checo_fifa
Debts['checo'] = Debts['checo']+1
TypeError: string indices must be integers
line 162 is:
if msg.startswith('$checo fifa'):
checo_fifa()
await message.channel.send('+1')
line 99 is:
def checo_fifa():
Debts['checo'] = Debts['checo']+1
Debts is a dictionary containing the key 'Checo' as well as a value of 0. There are some more usernames in the dictionary as well as functions pointing to all of them. Weirdly enough, the program worked for a while but now it only returns this when writing the command in discord.
Any help with this would be greatly appreciated.
You cannot add +1 to a string or a list, only to an integer. So you would have to convert this to a integer (if possible) e.g. with
def checo_fifa():
Debts['checo'] = int(Debts['checo']) + 1

Currently having an error with youtube-dl in python, any ideas?

This is the error I am getting, I tried to see if anyone else had this issue but it was only with other sites other than youtube and there was no fix listed. If needed I can link the python Code as well. This is happening when using a play command on a discord bot using discord.py-rewrite.
[youtube:search] query " www.youtube.com/watch?v=5abamRO41fE": Downloading page 1
ERROR: query " www.youtube.com/watch?v=5abamRO41fE": Failed to parse JSON (caused by JSONDecodeError('Expecting value: line 1 column 1 (char 0)')); please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see https://yt-dl.org/update on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
Ignoring exception in command play:
Traceback (most recent call last):
File "C:\Users\Jimmy\AppData\Local\Programs\Python\Python38-32\lib\site-packages\youtube_dl\extractor\common.py", line 904, in _parse_json
return json.loads(json_string)
File "C:\Users\Jimmy\AppData\Local\Programs\Python\Python38-32\lib\json\__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "C:\Users\Jimmy\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\Jimmy\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Jimmy\AppData\Local\Programs\Python\Python38-32\lib\site-packages\youtube_dl\YoutubeDL.py", line 797, in extract_info
ie_result = ie.extract(url)
File "C:\Users\Jimmy\AppData\Local\Programs\Python\Python38-32\lib\site-packages\youtube_dl\extractor\common.py", line 532, in extract
ie_result = self._real_extract(url)
File "C:\Users\Jimmy\AppData\Local\Programs\Python\Python38-32\lib\site-packages\youtube_dl\extractor\common.py", line 3014, in _real_extract
return self._get_n_results(query, n)
File "C:\Users\Jimmy\AppData\Local\Programs\Python\Python38-32\lib\site-packages\youtube_dl\extractor\youtube.py", line 3200, in _get_n_results
data = self._download_json(
File "C:\Users\Jimmy\AppData\Local\Programs\Python\Python38-32\lib\site-packages\youtube_dl\extractor\common.py", line 893, in _download_json
res = self._download_json_handle(
File "C:\Users\Jimmy\AppData\Local\Programs\Python\Python38-32\lib\site-packages\youtube_dl\extractor\common.py", line 879, in _download_json_handle
return self._parse_json(
File "C:\Users\Jimmy\AppData\Local\Programs\Python\Python38-32\lib\site-packages\youtube_dl\extractor\common.py", line 908, in _parse_json
raise ExtractorError(errmsg, cause=ve)
youtube_dl.utils.ExtractorError: query " www.youtube.com/watch?v=5abamRO41fE": Failed to parse JSON (caused by JSONDecodeError('Expecting value: line 1 column 1 (char 0)')); please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see https://yt-dl.org/update on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Jimmy\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "g:\Bots\TestBot\test.py", line 574, in play
results = ydl.extract_info(f'ytsearch1: {song_search}', download=True)
File "C:\Users\Jimmy\AppData\Local\Programs\Python\Python38-32\lib\site-packages\youtube_dl\YoutubeDL.py", line 820, in extract_info
self.report_error(compat_str(e), e.format_traceback())
File "C:\Users\Jimmy\AppData\Local\Programs\Python\Python38-32\lib\site-packages\youtube_dl\YoutubeDL.py", line 625, in report_error
self.trouble(error_message, tb)
File "C:\Users\Jimmy\AppData\Local\Programs\Python\Python38-32\lib\site-packages\youtube_dl\YoutubeDL.py", line 595, in trouble
raise DownloadError(message, exc_info)
youtube_dl.utils.DownloadError: ERROR: query " www.youtube.com/watch?v=5abamRO41fE": Failed to parse JSON (caused by JSONDecodeError('Expecting value: line 1 column 1 (char 0)')); please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see https://yt-dl.org/update on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.

Prgm_MAWS: "IndexError: list index out of range"

MAWS.py is a 4 years old program that uses Amber/AmberTools as calculation platform. Although I follow program user guide instructions, I do not know how to debug and find the solution to raise self._value IndexError: list index out of range
I replaced the force field(ff) specified in MAWS.py with a newer Amber ff.
As I am not familiar with python code and where the error could be generated I recommend to download the MAWS.py code from GitHub Repository: https://github.com/igemsoftware/Heidelberg_15
python3 MAWS_rev1.py -b 0.01 -i 200 -s 200 -l 15 -t 0.01 -f pdb -y HYBRID Prot1a.frcmod /home/bcramer/workdir-amber/Prot_1/
['DGN', 'DAN', 'DTN', 'DCN']
Choosing from candidates ...
Constructing Ligand/Aptamer complex ...
Constructing Ligand/Aptamer complex ...
etc..................
Loading Aptamer/Ligand complex ...
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
File "/home/bcramer/miniconda3/lib/python3.7/multiprocessing/pool.py", line 121, in worker
result = (True, func(*args, **kwds))
File "/home/bcramer/miniconda3/lib/python3.7/multiprocessing/pool.py", line 44, in mapstar
return list(map(*args))
File "MAWS_rev1.py", line 1090, in initial
ligand_range = get_ligand_range(aptamer_top.topology)
File "MAWS_rev1.py", line 197, in get_ligand_range
return [get_ligand(topology)[0], len(get_ligand(topology))]
IndexError: list index out of range
"""
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "MAWS_rev1.py", line 1357, in <module>
positions_and_Ntides = loop()
File "MAWS_rev1.py", line 1237, in loop
pos_Nt_S_task = pool.map(initial, alphabet)
File "/home/bcramer/miniconda3/lib/python3.7/multiprocessing/pool.py", line 268, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
File "/home/bcramer/miniconda3/lib/python3.7/multiprocessing/pool.py", line 657, in get
raise self._value
IndexError: list index out of range

python3 UnicodeError: encoding with 'idna' codec failed (UnicodeError: label empty or too long)

I am having some issues running my program. I have a "masterfile" that has a list of ips on a \n like so but I keep getting this error message:
68.x.0.56
68.x.0.53
I'm not sure what exactly the problem is, but I've been searching forums and other stackoverflow help, but can't seem to determine what the issue is.
def dns_resolver(subdomains):
print('\n\n########## Checking Subdomains for DNS Resolutions ##########\n')
queries = []
with open ('masterfile', 'r') as f:
domains = f.read().splitlines()
for i in domains:
try:
resp = socket.gethostbyname(i)
print(resp)
queries.append((i, resp))
except socket.error:
pass
return queries
Traceback (most recent call last):
File "/usr/lib/python3.6/encodings/idna.py", line 165, in encode
raise UnicodeError("label empty or too long")
UnicodeError: label empty or too long
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "subdomain-hunter.py", line 170, in <module>
main()
File "subdomain-hunter.py", line 59, in main
enumerate(DOMAIN)
File "subdomain-hunter.py", line 120, in enumerate
resolvediff = dns_resolver(diff)
File "subdomain-hunter.py", line 142, in dns_resolver
resp = socket.gethostbyname(i)
UnicodeError: encoding with 'idna' codec failed (UnicodeError: label empty or too long)

Resources