【发布时间】:2020-10-13 09:07:55
【问题描述】:
我是 discord.py 的新手,我想学习 python 并为我的服务器制作一个简单的机器人。 我想制作一个机器人,当有人加入服务器时发送消息。但机器人不会发送任何消息。我尝试了很多解决方案,但都没有奏效。
控制台没有错误。只是“on_member_join”不起作用; ping 和控制台消息方法有效。
这是我的代码:
import discord
from discord.ext import commands
client = commands.Bot(command_prefix='*')
TOKEN = '----my token here----'
@client.event
async def on_ready():
print('Bot is ready')
@client.event
async def on_member_join(member):
channel = client.get_channel(764960656553934879)
await channel.send('Hello')
@client.command()
async def ping(ctx):
await ctx.send('Pong!')
client.run(TOKEN)
【问题讨论】:
-
发现会员加入时on_member_join事件根本没有运行