G
G
Guerro692020-07-02 15:24:12
Python
Guerro69, 2020-07-02 15:24:12

Discord Bot how to get the exact server id from the on_member_join() event?

I am writing a bot in ds, the code is that during the on_member_join (member) event, the executable code took the id of the server on which the join took place and, using the function, accessed the database, which looked at the server id to see if there was a greeting for the user, if any , then the bot will send it to the user, if it is not there, then it will simply ignore it, but the question is how to get the exact server id in this event, if this function takes only one "member" argument, bot.guilds or client.guilds is not .
The code:

TOKEN= 'Token'
p = '.'
bot = commands.Bot(command_prefix=p)
tag = 'Bot -'

def get_greeting(guild):
  connect = connection()
  try:
    with connect.cursor() as cursor:
      result = cursor.execute(f"SELECT * FROM `chats` WHERE gui={guild}")
      row = cursor.fetchone()
      if str(row['greeting']) != 'null':
        return 1, str(row['greeting'])
      else:
        return 0, ' '
  finally:
    connect.close()

@bot.event
async def on_member_join(member):
  rez, greeting = get_greeting(Сюды ид сервера)
  if rez == 1:
    await member.send(f"{member.mention}, приветствуем тебя на сервере.\n{greeting}")

bot.run(TOKEN)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shurshur, 2020-07-02
@Guerro69

member.guild.id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question