Hiya, I've been trying to create a discord welcome message while also sending an embed to a joinlogs channel. This is my code so far:
import discord
from discord.ext import commands, tasks
import os
import asyncio
from dotenv import load_dotenv
load_dotenv(".env")
TOKEN: str = os.getenv("TOKEN")
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
bot = commands.Bot(command_prefix=".", intents=intents)
@tasks.loop(seconds=5)
async def status():
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="Veltrix Designs"))
@bot.event
async def on_ready():
print("Bot is ready!")
status.start()
try:
synced_commands = await bot.tree.sync()
print(f"Synced {len(synced_commands)} commands.")
except Exception as e:
print("An error with syncing application commands has occured:", e)
async def load():
for filename in os.listdir("./cogs"):
if filename.endswith(".py"):
await bot.load_extension(f"cogs.{filename[:-3]}")
async def main():
async with bot:
await load()
await bot.start(TOKEN)
asyncio.run(main())```
**Cog: joins.py**
```py
import discord
from discord.ext import commands
import datetime
import inflect
class Joins(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_ready(self):
print(f"{__name__} is online!")
@commands.Cog.listener()
async def on_member_join(self, member):
welcome_channel = self.bot.get.channel(1295335416911761428)
welcome_banner = ":W1::W2::W3::W4::W5::W6:"
ordinal_string = inflect.engine().ordinal(member.guild.member_count)
if welcome_channel:
await welcome_channel.send(f"{welcome_banner} Welcome to Veltrix Designs {member.mention}! You are our `{ordinal_string}` member! Use `/help` for more information about the server.")
joinlogs_channel = self.bot.get.channel(1295812487333023804)
if joinlogs_channel:
joinlogs_embed = discord.Embed(
color=discord.Color.blurple(),
description=f"{member.mention} has joined the server. They are the `{ordinal_string}` member."
)
joinlogs_embed.set_footer(
name=f"User ID: {member.id}"
)
joinlogs_embed.timestamp = datetime.datetime.now()
await joinlogs_channel.send(embed=joinlogs_embed)
async def setup(bot):
await bot.add_cog(Joins(bot))```
the problem I am facing is that when a user joins the guild it doesn't send a message/embed to the welcome_channel nor the joinlogs_channel.. How should I change my code to have this working?