diff --git a/.gitignore b/.gitignore index 43ca75b..a90ac83 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .venv/ venv/ -.idea/* \ No newline at end of file +.idea/* +__pycache__/ \ No newline at end of file diff --git a/cogs/say_hallo.py b/cogs/say_hallo.py new file mode 100644 index 0000000..c36a930 --- /dev/null +++ b/cogs/say_hallo.py @@ -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)) \ No newline at end of file diff --git a/main.py b/main.py index 53a6b58..c86be1f 100644 --- a/main.py +++ b/main.py @@ -6,6 +6,7 @@ from dotenv import load_dotenv intents = discord.Intents.default() intents.message_content = True # NOQA +intents.members = True # NOQA bot = discord.Bot(intents=intents, debug_guilds=[889424923859230720]) @@ -55,5 +56,10 @@ async def info( await ctx.respond(embed=embed) -load_dotenv() -bot.run(os.getenv("DISCORD_TOKEN")) +if __name__ == "__main__": + for filename in os.listdir("cogs"): + if filename.endswith(".py"): + bot.load_extension(f"cogs.{filename[:-3]}") + + load_dotenv() + bot.run(os.getenv("DISCORD_TOKEN"))