对客户端事件discord.py使用Bot命令

2024-04-19 17:38:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试创建一个使用客户机事件(如on_member_join)和命令(@bot.command())的不协调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)

如果有人能帮我,我将不胜感激


Tags: importeventasyncondefbot事件public
1条回答
网友
1楼 · 发布于 2024-04-19 17:38:44

我看到你在做欢迎词。你可以做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}!')

相关问题 更多 >