Every guild that the bot joins, add all the users to the table of members

pull/8/head
sgoudham 4 years ago
parent 98f8b27e8c
commit 0d48e904a2

@ -100,6 +100,24 @@ async def ping(ctx):
await ctx.send(f'Pong! `{round(client.latency * 1000)}ms`') await ctx.send(f'Pong! `{round(client.latency * 1000)}ms`')
# Bot event for the bot joining a new guild, storing all users in the database
@client.event
async def on_guild_join(guild):
try:
with db.connection() as conn:
for member in guild.members:
name = f"{member.name}#{member.discriminator}"
insert_query = """INSERT INTO members (guildID, discordUser, discordID) VALUES (?, ?, ?)"""
vals = guild.id, name, member.id,
cursor = conn.cursor()
cursor.execute(insert_query, vals)
conn.commit()
print(cursor.rowcount, f"Record inserted successfully into Members from {guild.name}")
except mariadb.Error as ex:
print("Parameterized Query Failed: {}".format(ex))
# Bot event for new member joining, sending an embed introducing them to the server # Bot event for new member joining, sending an embed introducing them to the server
@client.event @client.event
async def on_member_join(member): async def on_member_join(member):

Loading…
Cancel
Save