T
T
tatsuki12021-11-23 17:16:39
Python
tatsuki1, 2021-11-23 17:16:39

Problem with MongoDB, help please?

I am writing a greeting system, and I want that when they write prefix.welcome #channel, the bot enters data into the database, that is, the server id and channel id (I did this), then when you write the command again and select another channel, the data in the database according to this server id was updated, that is, the channel ID was updated if the server id already exists in the database.

@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 question

Ask a Question

731 491 924 answers to any question