import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='Please')
@bot.command()
async def _say(ctx, arg):
await ctx.send(arg)
@bot.event
async def on_member_join(member):
await client.get_channel(819281283803906071).send(f"{member.name} has joined")
bot.run('Token')
尝试制作一个机器人,当用户通过消息加入时,它会 @ 并欢迎用户。 这是代码,但在加入成员时没有任何反应,我什至没有收到错误消息。
答案 0 :(得分:0)
我在这里看到代码中有几个错误。
首先)您使用 bot
,但是使用 client.get_channel
查询频道,这没有任何意义。
第二)您必须为您的应用程序启用 Discord Developer Portal 中的意图。
您的整个活动:
intents = discord.Intents.all() # Imports all the Intents
bot = commands.Bot(command_prefix='Please', intents=intents) # Add the intents to your code
@bot.event
async def on_member_join(member):
channel = bot.get_channel(819281283803906071)
await channel.send(f"{member.name} has joined!")