[英]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基本上,您缺少这些
@commands.Cog.listener()
的
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>
确保您在 <YOUR_GUILD_ID> 中添加您的公会 ID
MAKE SURE YOU ADD A CUSTOM MESSAGE WHEN A MEMBER JOINS IN <WHAT_YOU_WANT>
确保在成员加入 <WHAT_YOU_WANT> 时添加自定义消息
MAKE SURE YOU ADD YOUR WELCOME CHANNEL ID IN <WELCOME_CHANNEL_ID>
请确保在 <WELCOME_CHANNEL_ID> 中添加您的欢迎频道 ID
MAKE SURE YOU ADD THE ROLE NAME THAT YOU GET WHEN A MEMBER JOINS IN <ROLE_NAME>
确保您添加了在成员加入 <ROLE_NAME> 时获得的角色名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.