Ive been trying to make a leveling system by following a youtube video and when im done with the code it keeps showing me this error again and again. I made sure that the username and password are correct but i might be silly enough to miss something else. I had whitelist IP address from anywhere to access the db and i host the bot on heroku.
The code:
@commands.Cog.listener()
async def on_message(self,message):
cluster = MongoClient("mongodb+srv://<BitterDBAdmin>:<hidden>@bitterbotdb.zwiwd.mongodb.net/BitterBotDB?retryWrites=true&w=majority")
lvl_system = cluster["BitterLevelDB"]["Leveling_System"]
xp_channel = 942567995312582676
message_xp_range = random.randint(10,35)
if message.channel.id == xp_channel:
if not message.author.bot:
stats = lvl_system.find_one({"id":message.author.id})
if stats is None:
new_user = {"id":message.author.id, "xp": 0}
lvl_system.insert_one(new_user)
else:
xp = stats["xp"] + message_xp_range
lvl_system.update_one({"id": message.author.id},{"$set":{"xp":xp}})
lvl = 0
while True:
if xp < ((50*(lvl**2))+(50*(lvl-1))):
break
lvl += 1
xp -= ((50*(lvl**2))+(50*(lvl-1)))
if xp == 0:
await message.channel.send(f"{message.author.mention} reached **{lvl}**\n*This feature is not completed.*")
The error:
File "C:\Python310\lib\site-packages\nextcord\client.py", line 415, in _run_event
await coro(*args, **kwargs)
File "d:\Bitter\VCS\Test Bot\Modules\Leveling System\codes.py", line 26, in on_message
stats = lvl_system.find_one({"id":message.author.id})
File "C:\Python310\lib\site-packages\pymongo\collection.py", line 1114, in find_one
for result in cursor.limit(-1):
File "C:\Python310\lib\site-packages\pymongo\cursor.py", line 1159, in next
if len(self.__data) or self._refresh():
File "C:\Python310\lib\site-packages\pymongo\cursor.py", line 1080, in _refresh
self.__send_message(q)
File "C:\Python310\lib\site-packages\pymongo\cursor.py", line 971, in __send_message
response = client._run_operation(
File "C:\Python310\lib\site-packages\pymongo\mongo_client.py", line 1215, in _run_operation
return self._retryable_read(
File "C:\Python310\lib\site-packages\pymongo\mongo_client.py", line 1307, in _retryable_read
with self._secondaryok_for_server(read_pref, server, session) as (
File "C:\Python310\lib\contextlib.py", line 135, in __enter__
return next(self.gen)
File "C:\Python310\lib\site-packages\pymongo\mongo_client.py", line 1162, in _secondaryok_for_server
with self._get_socket(server, session) as sock_info:
File "C:\Python310\lib\contextlib.py", line 135, in __enter__
return next(self.gen)
File "C:\Python310\lib\site-packages\pymongo\mongo_client.py", line 1099, in _get_socket
with server.get_socket(
File "C:\Python310\lib\contextlib.py", line 135, in __enter__
return next(self.gen)
File "C:\Python310\lib\site-packages\pymongo\pool.py", line 1371, in get_socket
sock_info = self._get_socket(all_credentials)
File "C:\Python310\lib\site-packages\pymongo\pool.py", line 1483, in _get_socket
sock_info = self.connect(all_credentials)
File "C:\Python310\lib\site-packages\pymongo\pool.py", line 1337, in connect
sock_info.check_auth(all_credentials)
File "C:\Python310\lib\site-packages\pymongo\pool.py", line 814, in check_auth
self.authenticate(credentials)
File "C:\Python310\lib\site-packages\pymongo\pool.py", line 831, in authenticate
auth.authenticate(credentials, self)
File "C:\Python310\lib\site-packages\pymongo\auth.py", line 548, in authenticate
auth_func(credentials, sock_info)
File "C:\Python310\lib\site-packages\pymongo\auth.py", line 469, in _authenticate_default
return _authenticate_scram(credentials, sock_info, 'SCRAM-SHA-1')
File "C:\Python310\lib\site-packages\pymongo\auth.py", line 205, in _authenticate_scram
res = sock_info.command(source, cmd)
File "C:\Python310\lib\site-packages\pymongo\pool.py", line 719, in command
return command(self, dbname, spec, secondary_ok,
File "C:\Python310\lib\site-packages\pymongo\network.py", line 158, in command
helpers._check_command_response(
File "C:\Python310\lib\site-packages\pymongo\helpers.py", line 170, in _check_command_response
raise OperationFailure(errmsg, code, response, max_wire_version)
pymongo.errors.OperationFailure: bad auth : Authentication failed., full error: {'ok': 0, 'errmsg': 'bad auth : Authentication failed.', 'code': 8000, 'codeName': 'AtlasError'}
Is there any way to solve this?