我希望我的discord bot在每次新用户加入服务器时发送特定频道的消息并给出特定角色
但是我的bot什么也没做,我也没有得到任何错误
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!")
用户问候语代码(在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}!")
基本上,你错过了这些@commands.Cog.listener()
试试这个!
@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>")
这使得当有人加入您的服务器时,它将发送您选择的自定义消息到欢迎频道
确保你在
确保在成员加入
时添加自定义消息
确保在<lt;WELCOME_CHANNEL_ID>
确保添加了成员加入时获得的角色名