我正在尝试制作一个使用客户端事件(例如 on_member_join
)和命令 (@bot.command()
) 的 Discord Python Bot。 on_member_join
事件不适用于 @bot.event
,但 on_ready
工作正常。
代码如下:
import discord
from discord.ext import commands
import os
bot = commands.Bot(command_prefix='$')
@bot.event
async def on_member_join(member):
public = 'welcome, {0.mention}:'.format(member)
await member.guild.system_channel.send(public)
@bot.command()
async def ping(ctx):
await ctx.send('pong :sunglasses:')
bot.run(TOKEN)
如果有人帮助我,我将不胜感激。
答案 0 :(得分:0)
我看到您正在尝试发送欢迎信息。你可以做 ctx.send 而不是 member.send 你只需要传入 ctx。
这是我的欢迎信息:
#Welcome DM
@bot.event
async def on_member_join(member):
await member.send(f'Hey {member.mention}, thanks for joining {member.guild.name}!')