Answer the question
In order to leave comments, you need to log in
Instead of replacing, MongoDB is written again, can you help?
I am writing one system with a MongoDB database, and I want that when the database by server ID is empty, data is entered, and when the server ID matches the server ID that is recorded in the database, the data is replaced, not written again.
@commands.command()
async def welcome(self, ctx, channel: discord.TextChannel):
if ctx.message.author.guild_permissions.manage_messages:
result = channel1.find_one({"guild_id": ctx.guild.id, "channel_id": channel.id})
if result is None:
channel1.insert_one({f"guild_id": ctx.guild.id, "channel_id": channel.id})
await ctx.send(f'{ctx.author.mention}, канал успешно установлен на {channel.mention}.')
elif result is not None:
channel1.update_one({"guild_id": ctx.guild.id}, {"$set": {"channel_id": channel.id}})
await ctx.send(f'{ctx.author.mention}, канал изменён на {channel.mention}.')
else:
await ctx.send(f'{ctx.author.mention}, вам нужны права на управлени
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question