import nextcord
from nextcord.ext import commands
import sqlite3
intents = nextcord.Intents.default()
intents.member_join = True
bot = commands.Bot(command_prefix="!", intents=intents)
conn = sqlite3.connect('invites.db')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS settings (
guild_id INTEGER PRIMARY KEY,
channel_id INTEGER
)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS invites (
user_id INTEGER PRIMARY KEY,
inviter_id INTEGER,
FOREIGN KEY (inviter_id) REFERENCES invites (user_id)
)
''')
conn.commit()
@bot.event
async def on_member_join(member):
chann = None
guild = member.guild
cursor.execute('''
SELECT channel_id FROM settings WHERE guild_id = ?
''', (guild.id,))
result = cursor.fetchone()
if result:
channel_id = result[0]
chann = bot.get_channel(channel_id)
inviter_id = None
total_invites = 0
cursor.execute('''
SELECT inviter_id FROM invites WHERE user_id = ?
''', (member.id,))
result = cursor.fetchone()
if result is not None:
inviter_id = result[0]
cursor.execute('''
SELECT COUNT(user_id) FROM invites WHERE inviter_id = ?
''', (inviter_id,))
result = cursor.fetchone()
if result is not None:
total_invites = result[0]
if chann:
embed = nextcord.Embed(
title='Leafy InviteLogger',
description=f'{member.mention} join the server!\n\n Invited by <@{inviter_id}>\n Total invitations {total_invites}',
colour=0x2b2d31
)
embed.set_footer(text='https://elezthem.w3spaces.com/')
await chann.send(embed=embed)
@bot.command()
@commands.has_permissions(administrator=True)
async def set_channel(ctx, channel: nextcord.TextChannel):
if ctx.author.guild_permissions.administrator:
cursor.execute('''
INSERT OR REPLACE INTO settings (guild_id, channel_id)
VALUES (?, ?)
''', (ctx.guild.id, channel.id))
conn.commit()
await ctx.send(f'The invitation registration channel is set to {channel.mention}')
else:
await ctx.send('You do not have permission to run this command.')
@bot.command()
async def invites(ctx):
user = ctx.author
total_invites = 0
cursor.execute('''
SELECT inviter_id FROM invites WHERE user_id = ?
''', (user.id,))
result = cursor.fetchone()
if result is not None:
inviter_id = result[0]
cursor.execute('''
SELECT COUNT(user_id) FROM invites WHERE inviter_id = ?
''', (inviter_id,))
result = cursor.fetchone()
if result is not None:
total_invites = result[0]
embed = nextcord.Embed(
title='Leafy InviteLogger',
description=f"\n**User**: {user.mention}\n\nTotal number of **invited** users: ``{total_invites}``",
colour=0x2b2d31
)
await ctx.send(embed=embed)
@bot.event
async def on_ready():
print('Bot is ready')
bot.run('YOUR_TOKEN')