Compare commits
2
Commits
v3.0.6
...
62-dm-on-join
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cc10bb518c | ||
|
|
90131f6395 |
@@ -4,6 +4,7 @@ Defines cog for guild listeners. Contains functions for various guild events.
|
|||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
from sqlalchemy import select
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
@@ -20,12 +21,24 @@ class GuildListener(commands.Cog, name="Guild Listener"):
|
|||||||
async def on_guild_join(self, guild: nextcord.Guild):
|
async def on_guild_join(self, guild: nextcord.Guild):
|
||||||
"""Listener for Guild Join. Adds guild to database."""
|
"""Listener for Guild Join. Adds guild to database."""
|
||||||
|
|
||||||
new_guild = Guild(GuildId=guild.id, GuildName=guild.name)
|
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
|
stmt = select(Guild).where(Guild.GuildId == guild.id)
|
||||||
|
guild_data = session.scalar(stmt)
|
||||||
|
|
||||||
|
# just in case check if the guild already exists
|
||||||
|
if guild_data is None:
|
||||||
|
new_guild = Guild(GuildId=guild.id, GuildName=guild.name)
|
||||||
session.add(new_guild)
|
session.add(new_guild)
|
||||||
|
else:
|
||||||
|
guild_data.GuildName = guild.name
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
# let imcompiling#2272 know about a new server joining!
|
||||||
|
# staying with fetch due to intents not being set up correctly. Maybe change to get eventually.
|
||||||
|
imcompiling: nextcord.User = await self.bot.fetch_user(206602713511886849)
|
||||||
|
await imcompiling.send(f'Agon has joined server "{guild.name}"!')
|
||||||
|
|
||||||
|
|
||||||
# This function will be called when this extension is loaded.
|
# This function will be called when this extension is loaded.
|
||||||
# It is necessary to add these functions to the bot.
|
# It is necessary to add these functions to the bot.
|
||||||
|
|||||||
Reference in New Issue
Block a user