mirror of
https://github.com/jcreek/discord.py-welcome-bot.git
synced 2026-07-14 19:33:43 +00:00
Update welcome-bot.py
This commit is contained in:
+19
-13
@@ -4,9 +4,9 @@
|
|||||||
# import all necessary commands and libraries
|
# import all necessary commands and libraries
|
||||||
import discord
|
import discord
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
client=discord.Client()
|
client=discord.Client()
|
||||||
|
welcomechannel = await client.fetch_channel(channel_id) #https://support.discord.com/hc/en-us/articles/206346498-Where-can-I-find-my-User-Server-Message-ID
|
||||||
|
# Make sure you get the ID of your channel by right-clicking it and clicking `Copy ID`. Make sure developer mode is on!
|
||||||
@client.event
|
@client.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
print('logged in as')
|
print('logged in as')
|
||||||
@@ -28,20 +28,26 @@ here!
|
|||||||
async def on_member_join(member):
|
async def on_member_join(member):
|
||||||
print("Recognised that a member called " + member.name + " joined")
|
print("Recognised that a member called " + member.name + " joined")
|
||||||
try:
|
try:
|
||||||
await client.send_message(member, newUserMessage)
|
await client.send_message(member, newUserMessage)
|
||||||
print("Sent message to " + member.name)
|
print("Sent message to " + member.name)
|
||||||
except:
|
except:
|
||||||
print("Couldn't message " + member.name)
|
print("Couldn't message " + member.name)
|
||||||
|
embed=discord.Embed(
|
||||||
|
title="Welcome "+member.name+"!"
|
||||||
|
description="We're so glad you're here!"
|
||||||
|
color=discord.Color.green()
|
||||||
|
)
|
||||||
|
|
||||||
# give member the steam role here
|
role = discord.utils.get(member.server.roles, name="name-of-your-role") # Gets the member role as a `role` object
|
||||||
## to do this the bot must have 'Manage Roles' permission on server, and role to add must be lower than bot's top role
|
await client.add_roles(member, role) # Gives the role to the user
|
||||||
role = discord.utils.get(member.server.roles, name="name-of-your-role")
|
|
||||||
await client.add_roles(member, role)
|
|
||||||
print("Added role '" + role.name + "' to " + member.name)
|
print("Added role '" + role.name + "' to " + member.name)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_member_leave(member):
|
||||||
|
print("Recognised that a member called " + member.name + " left")
|
||||||
|
embed=discord.Embed(
|
||||||
|
title="😢 Goodbye "+member.name+"!",
|
||||||
|
description="Until we meet again old friend." #A description isn't necessary, you can delete this line if you don't want a description.
|
||||||
|
color=discord.Color.red() #There are lots of colors, you can check them here: https://discordpy.readthedocs.io/en/latest/api.html?highlight=discord%20color#discord.Colour
|
||||||
|
)
|
||||||
client.run('token')
|
client.run('token')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user