Add Part 5
This commit is contained in:
parent
871479f796
commit
3778e3e203
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
.venv/
|
.venv/
|
||||||
venv/
|
venv/
|
||||||
.idea/*
|
.idea/*
|
||||||
|
__pycache__/
|
||||||
37
cogs/say_hallo.py
Normal file
37
cogs/say_hallo.py
Normal 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))
|
||||||
6
main.py
6
main.py
@ -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"))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user