added join an leave msgs and reduced outpud blob on exit
This commit is contained in:
1 parent
4d34daa1e7
commit
b3c7b34863
2 files changed
+64
-2
No files matched your search
@@ -0,0 +1,48 @@
|
|||||||
|
import os
|
||||||
|
import discord
|
||||||
|
from discord.ext import commands
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
class JoinLeave(commands.Cog):
|
||||||
|
def __init__(self, bot):
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_member_join(self, member):
|
||||||
|
if member.guild.id != int(os.getenv("GUILD_ID")):
|
||||||
|
return
|
||||||
|
|
||||||
|
channel = member.guild.get_channel(int(os.getenv("JOIN_LEAVE_CHANNEL_ID")))
|
||||||
|
if channel:
|
||||||
|
embed = discord.Embed(
|
||||||
|
title="Join👋",
|
||||||
|
description=f"Hey {member.mention} !\nWilkommen auf dem Server :3\nwelcome to the server :3",
|
||||||
|
color=3407664
|
||||||
|
)
|
||||||
|
embed.set_thumbnail(url=member.display_avatar.url)
|
||||||
|
embed.set_footer(text=f"Member count: {member.guild.member_count}")
|
||||||
|
|
||||||
|
await channel.send(embed=embed)
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_member_remove(self, member):
|
||||||
|
if member.guild.id != int(os.getenv("GUILD_ID")):
|
||||||
|
print("NOT GUILD")
|
||||||
|
return
|
||||||
|
|
||||||
|
channel = member.guild.get_channel(int(os.getenv("JOIN_LEAVE_CHANNEL_ID")))
|
||||||
|
if channel:
|
||||||
|
embed = discord.Embed(
|
||||||
|
title="Leave👋",
|
||||||
|
description=f"{member.mention} \nHat den Server verlassen :c\nhas left the server :c",
|
||||||
|
color=16711680
|
||||||
|
)
|
||||||
|
embed.set_thumbnail(url=member.display_avatar.url)
|
||||||
|
embed.set_footer(text=f"Member count: {member.guild.member_count}")
|
||||||
|
|
||||||
|
await channel.send(embed=embed)
|
||||||
|
|
||||||
|
async def setup(bot):
|
||||||
|
await bot.add_cog(JoinLeave(bot))
|
||||||
@@ -9,6 +9,7 @@ load_dotenv()
|
|||||||
|
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
intents.message_content = True
|
intents.message_content = True
|
||||||
|
intents.members = True
|
||||||
|
|
||||||
bot = commands.Bot(command_prefix=None, intents=intents)
|
bot = commands.Bot(command_prefix=None, intents=intents)
|
||||||
|
|
||||||
@@ -36,12 +37,25 @@ async def load_extensions():
|
|||||||
if filename.endswith(".py"):
|
if filename.endswith(".py"):
|
||||||
await bot.load_extension(f"commands.{filename[:-3]}")
|
await bot.load_extension(f"commands.{filename[:-3]}")
|
||||||
print(f"Loaded extension: commands.{filename[:-3]}")
|
print(f"Loaded extension: commands.{filename[:-3]}")
|
||||||
|
|
||||||
|
for filename in os.listdir("./extensions"):
|
||||||
|
if filename.endswith(".py"):
|
||||||
|
await bot.load_extension(f"extensions.{filename[:-3]}")
|
||||||
|
print(f"Loaded extension: extensions.{filename[:-3]}")
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
async with bot:
|
async with bot:
|
||||||
bot.database = Database()
|
bot.database = Database()
|
||||||
|
|
||||||
await load_extensions()
|
await load_extensions()
|
||||||
await bot.start(os.getenv("DISCORD_TOKEN"))
|
|
||||||
|
try:
|
||||||
|
await bot.start(os.getenv("DISCORD_TOKEN"))
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
|
||||||
asyncio.run(main())
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
asyncio.run(main())
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("\nShutting down... byeeeeee :3 👋")
|
||||||
Reference in new issue
Block a user