Compare commits

..

3 Commits
Part4 ... main

Author SHA1 Message Date
cc02629af2 Merge pull request 'Add Part 5' (#3) from Part5 into main
Reviewed-on: #3
2025-04-07 22:09:10 +02:00
3778e3e203 Add Part 5 2025-04-07 22:08:03 +02:00
871479f796 Merge pull request 'Add code for Part 4 ( Embed )' (#2) from Part4 into main
Reviewed-on: #2
2025-04-06 23:09:07 +02:00
3 changed files with 47 additions and 3 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.venv/ .venv/
venv/ venv/
.idea/* .idea/*
__pycache__/

37
cogs/say_hallo.py Normal file
View File

@ -0,0 +1,37 @@
# Für dieses Beispiel muss der Server Member Intent im Dev Portal und in der Main-Datei aktiviert sein
#
# intents = discord.Intents.default()
# intents.members = True
#
# bot = discord.Bot(
# intents=intents,
# debug_guilds=[123456789], # hier server id einfügen
# )
import discord
from discord.ext import commands
from discord.commands import slash_command
class Base(commands.Cog):
def __init__(self, bot):
self.bot = bot
@slash_command()
async def say_hallo(self, ctx):
await ctx.respond(f"Hey {ctx.author.mention}")
@commands.Cog.listener()
async def on_member_join(self, member):
embed = discord.Embed(
title="Willkommen",
description=f"Hey {member.mention}",
color=discord.Color.orange()
)
channel = await self.bot.fetch_channel(123456789) # hier channel id einfügen
await channel.send(embed=embed)
def setup(bot):
bot.add_cog(Base(bot))

View File

@ -6,6 +6,7 @@ from dotenv import load_dotenv
intents = discord.Intents.default() intents = discord.Intents.default()
intents.message_content = True # NOQA intents.message_content = True # NOQA
intents.members = True # NOQA
bot = discord.Bot(intents=intents, debug_guilds=[889424923859230720]) bot = discord.Bot(intents=intents, debug_guilds=[889424923859230720])
@ -55,5 +56,10 @@ async def info(
await ctx.respond(embed=embed) await ctx.respond(embed=embed)
if __name__ == "__main__":
for filename in os.listdir("cogs"):
if filename.endswith(".py"):
bot.load_extension(f"cogs.{filename[:-3]}")
load_dotenv() load_dotenv()
bot.run(os.getenv("DISCORD_TOKEN")) bot.run(os.getenv("DISCORD_TOKEN"))