DMing The Member Joins The Server - Discord.Py - python

#client.event
async def on_member_join(member):
channel = client.get_channel(659080736229294130)
await channel.send(f'{member.mention} Katıldı, Hoşgeldin! {channel.guild.member_count} Kişiyiz!')
role = get(member.guild.roles, name=ROLE)
await member.add_roles(role)
print(f"{member} Katıldı!")
if member.guild is None and not member.author.bot:
async with member.typing():
await asyncio.sleep(0.7)
embed = discord.Embed(
title="Hoşgeldin!",
colour=discord.Colour.blue(),
)
embed.set_thumbnail(
url="https://cdn.discordapp.com/avatars/649985273249398784/493fe440660d331687e426ba976da8f4.webp?size=1024")
embed.add_field(name="‎",
value="**TEXT**",
inline=False)
embed.add_field(name="TEXT",
value= "TEXT", )
embed.set_footer(text="© #MakufonSkifto#0432")
await member.send(embed=embed)
The code you see is under
#client.event
async def on_member_join(member):
I want my bot to DM the person who joins the server. I have made a command that welcomes the newcomer thru the welceme channel but I couldn't make DM work. And as the bot didn't know what message is, It makes the text red. When I put message on the top It says "message is a required context that is missing" when someone joins. I don't know how to proceed but I definitely need you guys help! I can give the full on_member_joins event if you guys want

You can send personal messages to a user through member.send(...) where member is the user in the context (joined the server).
The <destination>.send(<content>) function sends the content(your message) to the given destination which can be a channel, a group or a member(in this case),etc.
Here is a sample code(your code with some changes) which send an embed to the joining user's DM:
#client.event
async def on_member_join(member):
print ("{} joined!".format(member.name))
print (f'{member.guild.name}')
await member.send("Welcome!")
role = member.guild.roles
# member.guild.roles returns an object of type <class 'list'>
if member.guild and not member.bot:
async with member.typing():
embed = discord.Embed(
title="Hoşgeldin!",
colour=discord.Colour.blue(),
)
embed.set_thumbnail(
url="https://cdn.discordapp.com/avatars/649985273249398784/493fe440660d331687e426ba976da8f4.webp?size=1024")
embed.add_field(name="something",
value="**TEXT**",
inline=False)
embed.add_field(name="TEXT",
value="TEXT")
embed.set_footer(text="© #MakufonSkifto#0432")
await member.send(embed=embed)

Related

How can my discord bot send a welcome message and give a role

I want that my discord bot sends a message on a specific channel and give a specific role everytime a new user joins the server
But my bot is doing nothing and I'm getting no errors
import discord
from keep_alive import keep_alive
class MyClient(discord.Client):
#Beim Einloggen
async def on_ready(self):
print("BOT is online")
async def on_member_join(member):
role = discord.utils.get(member.server.roles, id=<role_id>)
channel = MyClient.get_channel(<channel_id>)
await MyClient.add_roles(member, role)
await channel.send(f"Hello {member} nice to see you!")
Code for the user greeting (in a cog):
#commands.Cog.listener()
async def on_member_join(self, member):
channel = member.guild.system_channel
if channel is not None:
await channel.send(f"Welcome to the server {member.mention}!")
Basically, you are missing theese #commands.Cog.listener()'s
Try this! (This isn't used in a cog)
#client.event
async def on_member_join(member):
if member.guild.id !=<YOUR_GUILD_ID>:
return
welcomerole = discord.utils.get(guild.roles, name="<ROLE_NAME>")
await member.add_roles(welcomerole)
channel = client.get_channel(<WELCOME_CHANNEL_ID)
await channel.send("<WHAT_YOU_WANT>")
This makes it so when someone joins YOUR server it will send a custom message of your choice to the welcome channel
MAKE SURE YOU ADD YOUR GUILD ID IN <YOUR_GUILD_ID>
MAKE SURE YOU ADD A CUSTOM MESSAGE WHEN A MEMBER JOINS IN <WHAT_YOU_WANT>
MAKE SURE YOU ADD YOUR WELCOME CHANNEL ID IN <WELCOME_CHANNEL_ID>
MAKE SURE YOU ADD THE ROLE NAME THAT YOU GET WHEN A MEMBER JOINS IN <ROLE_NAME>

Why doesn't my discord.py welcome message work?

I have this code I used before. But it suddenly stopped working. I can't figure out how to fix this.
#bot.event
async def on_member_join(member):
guild = bot.get_guild(guild_id)
embed = discord.Embed(title="Welcome", description=f"Hi {member.mention} welcome to {guild.name}")
embed.set_footer(text="UnhelpfulBOT© | Made by Kezz#4058")
await bot.get_channel(channel_id).send(content=None, embed=embed)```
First let's get the guild not via some magic variables but through the member who joined (Documentation)
#bot.event
async def on_member_join(member):
guild = member.guild
embed = discord.Embed(title="Welcome", description=f"Hi {member.mention} welcome to {guild.name}")
embed.set_footer(text="UnhelpfulBOT© | Made by Kezz#4058")
Now we need to send the message in the channel the member joined.
The general channel where members join is the guild.system_channel (Documentation). If this channel is not set, we do not send a message.
system_channel = guild.system_channel
if system_channel is None:
print('No system channel found')
else:
await.send(embed = embed)
Your code has a few errors, and I think this is more of what your code should look like. As for you not receiving any error message, that is a very odd thing that I'm not sure why is happening.
#bot.event
async def on_member_join(member):
guild = await bot.get_guild(guild_id)
embed = discord.Embed(
title = "Welcome",
description = f"Hi {member.mention} welcome to {guild.name}"
)
embed.set_footer(text = "UnhelpfulBOT© | Made by Kezz#4058")
channel = await bot.get_channel(channel_id)
await channel.send(embed = embed)

discord.py - adding reaction as part of command

I'm writing a custom help command that sends a embed DM to a user, that all works fine. As part of the command, I'm trying to make the bot react to the command message but I cannot get it to work, I've read the documentation but I still can't seem to get it to react as part of a command. Below is the what I'm trying to achieve:
#client.command(pass_context=True)
async def help(ctx):
# React to the message
author = ctx.message.author
help_e = discord.Embed(
colour=discord.Colour.orange()
)
help_e.set_author(name='The bot\'s prefix is !')
help_e.add_field(name='!latency', value='Displayes the latency of the bot', inline=False)
help_e.add_field(name='!owo, !uwu, !rawr', value='Blursed commands', inline=False)
await author.send(embed=help_e)```
You can use message.add_reaction() and also you can use ctx.message to add reaction to the message. Here is what you can do:
#client.command(pass_context=True)
async def help(ctx):
# React to the message
await ctx.message.add_reaction('✅')
author = ctx.message.author
help_e = discord.Embed(
colour=discord.Colour.orange()
)
help_e.set_author(name='The bot\'s prefix is !')
help_e.add_field(name='!latency', value='Displayes the latency of the bot', inline=False)
help_e.add_field(name='!owo, !uwu, !rawr', value='Blursed commands', inline=False)
sent_embed = await author.send(embed=help_e)

Trying to figure out why my bot wont send an embed to the channel

I made a script that sends an embed via a webhook, it works just fine but I am trying to convert it to send via the bot into the same channel. I cant seem to figure that out (I have never used the bot to send embeds before.)
async def start(keyword):
SOME CODE HERE
await embeded(channel)
async def embeded(channel):
# Discord Embed Setup
embed = Embed(
description=f"[**eBay Link**]({eBayLink})",
color=0x0d0d22,
timestamp='now' # sets the timestamp to current time
)
embed.set_author(name=Titles)
embed.add_field(name='Average', value=Averages, inline=True)
embed.add_field(name='Lowest', value=Lowests, inline=True)
embed.add_field(name='Highest', value=Highests, inline=True)
embed.add_field(name='Margin', value=Margins, inline=True)
embed.add_field(name='Postage', value=Postages, inline=True)
embed.set_footer(text='TEST', icon_url='IMAGE')
embed.set_thumbnail(image.get_attribute('src'))
await channel.send(embed=embed)
print("Embed sent to discord!")
#client.event
async def on_ready():
print("Bot is online!")
#client.event
async def on_message(message):
if message.content.startswith('!flip '):
keyword = message.content.split('!flip ')[1]
await start(keyword, channel)
client.run(token)
I get the error
await start(keyword, channel)
NameError: name 'channel' is not defined
You need to add channel parameter to the function also.
You should pass message.channel instead of channel.
Indent start function in the if statement of on_message.
Function Edits:
async def start(keyword, channel):
#Code
await embeded(channel)
on_message Edits:
#client.event
async def on_message(message):
if message.content.startswith('!flip '):
keyword = message.content.split('!flip ')[1]
await start(keyword, message.channel)

Sending a message on a user join event - discord.py

I've been programming a bot that welcomes a user when they join but it doesn't seem to be working.
async def on_member_join(member):
channel = member.channel
await channel.send(f'{member} has arrived')
You haven't specified where the channel is that you want to send the message to, and discord.Member doesn't have an attribute called channel.
You'll have to get the channel via its ID, like so:
async def on_member_join(member):
channel = bot.get_channel(112233445566778899) # replace id with the welcome channel's id
await channel.send(f"{member} has arrived!")
If you want to, you can also get it via its name:
async def on_member_join(member):
channel = discord.utils.get(member.guild.text_channels, name="welcome")
await channel.send(f"{member} has arrived!")
References:
on_member_join()
Client.get_channel()
Guild.text_channels
Member.guild
utils.get()
#client.event
async def on_member_join(member):
for channel in member.guild.channels:
if str(channel) == "member-log":
await channel.send(f"""Welcome {member.mention}!""")
This might help too. Here, we are checking if the channel name is member-log and then sending a welcome message to that channel.

Categories