【问题标题】:Using Bot commands with client events - discord.py使用带有客户端事件的 Bot 命令 - discord.py
【发布时间】:2021-05-11 00:31:49
【问题描述】:

我正在尝试制作一个使用客户端事件(例如 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)

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

【问题讨论】:

  • 你定义了意图吗?

标签: python python-3.x discord discord.py


【解决方案1】:

我看到您正在尝试发送欢迎信息。你可以用 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}!')

【讨论】:

    猜你喜欢
    • 2021-06-12
    • 2020-12-24
    • 1970-01-01
    • 2019-08-22
    • 2019-10-15
    • 1970-01-01
    • 1970-01-01
    • 2020-08-16
    • 2019-07-23
    相关资源
    最近更新 更多