#πŸ”’ Discord Welcome Message | Not Sending | Fixed

35 messages Β· Page 1 of 1 (latest)

rustic gate
#

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:

main.py

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?
wary sigilBOT
#

@rustic gate

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

rustic gate
#

Discord Welcome Message | Not Sending

modest garnet
rustic gate
modest garnet
#

can you elaborate more on how the embed is broken

rustic gate
#

Doesn't send the embed. Nor prints the content of the channel and embed in:

Cog: joins.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()
            print(joinlogs_embed)
            print(joinlogs_channel)
            await joinlogs_channel.send(embed=joinlogs_embed)


async def setup(bot):
    await bot.add_cog(Joins(bot))```
modest garnet
#

does it post the message in the welcome channel at least (the one without the embed?)

rustic gate
#

yeah

modest garnet
#

move the print(joinlogs_channel) above the if

#
print(joinlogs_channel)
if joinlogs_channel:
  ...
rustic gate
modest garnet
#

hmm

#

do you happen to have any error handlers anywhere?

rustic gate
modest garnet
#

right, but any error handlers in any other cogs? or the main file?

rustic gate
#

the problem is the embed I think but idk why

rustic gate
modest garnet
#

can you paste all of them

#

there is a common mistake people make with error handlers that makes them not see any errors

rustic gate
#

main.py

@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)```

πŸ’€
#

Think that's the only one, (i have 3 cogs)

modest garnet
#

no i mean, a global error handler, it'll usually be a function named on_error or on_command_error or similar

rustic gate
#

none

modest garnet
#

hmm. ok well set_footer doesn't name a name argument, it just takes text

rustic gate
#

-# kinda new to python mb lol

modest garnet
#

joinlogs_embed.set_footer(name="...")

rustic gate
#

erm

#

lemme try text lol

#

ty lol

#

Discord Welcome Message | Not Sending | Fixed

#

!close

wary sigilBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.