X
X
x4zx2021-12-04 03:37:11
Python
x4zx, 2021-12-04 03:37:11

How to check for ID presence?

Hello, I'm making a bot ticket. There is a function to automatically send a ticket menu to the specified channel, it is specified using a command and the channel ID is entered into the database.

Code below:

channel = guild.get_channel(collticku.find_one({'_id': guild.id})['channel_id'])

            if not channel:
                return
            else:


There is a minus in this code, if at least one of the listed servers in the database does not specify a channel for sending the ticket menu, then the ticket menu will not be sent to more than one server. Including even those whose channel is specified. Please help me to do the correct check.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
antares4045, 2021-12-04
@antares4045

row = collticku.find_one({'_id': guild.id})
if not row or not ('channel_id' in row):
  return
channel = guild.get_channel(row.get('channel_id'))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question