Я создаю бота с базами данных для дискорда. При разработке столкнулся с данной проблемой: при каждой попытке вывести баланс человека, выводится данная ошибка в консоль
raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: cluster0-shard-00-00.bn6du.mongodb.net:27017: connection closed,cluster0-shard-00-02.bn6du.mongodb.net:27017: connection closed,cluster0-shard-00-01.bn6du.mongodb.net:27017: connection closed, Timeout: 30s, Topology Description: <TopologyDescription id: 6256e1b6ca5089d0ea20fe00, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('cluster0-shard-00-00.bn6du.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('cluster0-shard-00-00.bn6du.mongodb.net:27017: connection closed')>, <ServerDescription ('cluster0-shard-00-01.bn6du.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('cluster0-shard-00-01.bn6du.mongodb.net:27017: connection closed')>, <ServerDescription ('cluster0-shard-00-02.bn6du.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('cluster0-shard-00-02.bn6du.mongodb.net:27017: connection closed')>]>
Код самого бота:
import discord
from discord.ext import commands
from pymongo import MongoClient
import sys
cluster = MongoClient("")
bot = commands.Bot(command_prefix='b.')
@bot.remove_command('help')
@bot.event
async def on_ready():
print("Bot connected to the server")
await bot.change_presence(status = discord.Status.online, activity = discord.Game('b.help'))
@bot.event
async def on_message(message):
if collection.count_documents({f'money{message.guild.id}':message.author.id}) == 0:
collection.insert_one({f'money{message.guild.id}':message.author.id, 'count': 1})
await bot.process_commands(message)
else:
collection.update_one({f'money{message.guild.id}': message.author.id}, {'$inc': {'count': 1}})
await bot.process_commands(message)
@bot.command()
async def check_balance(ctx):
if collection.count_documents({f'money{ctx.guild.id}': ctx.author.id}) == 1:
await ctx.send('money: ' + str(collection.find_one({f'money{ctx.guild.id}': ctx.author.id})['count']))
else:
print('false')
bot.run('')