import discord
client = discord.Client()
@client.event
async def on_member_join(member):
# Send a message to the welcome channel
welcome_channel = member.guild.get_channel(CHANNEL_ID)
await welcome_channel.send(f"Welcome {member.mention} to the server!")
client.run(TOKEN)
每当我尝试运行此代码替换令牌和通道ID时,它都会显示一个错误,如:
Traceback (most recent call last):
File "main.py", line 3, in <module>
client = discord.Client()
TypeError: __init__() missing 1 required keyword-only argument: 'intents'
KeyboardInterrupt
根据快速入门文档(和错误消息),您需要指定要使用的意图。
下面是一个使用默认意图的例子:
import discord
intents = discord.Intents.default()
client = discord.Client(intents=intents)
@client.event
async def on_member_join(member):
# Send a message to the welcome channel
welcome_channel = member.guild.get_channel(CHANNEL_ID)
await welcome_channel.send(f"Welcome {member.mention} to the server!")
client.run(TOKEN)