Discord.py on_member_join 不起作用,没有错误消息

2023-05-13Python开发问题
6

本文介绍了Discord.py on_member_join 不起作用,没有错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试使用 Discord.py 库制作一个不和谐机器人.带有 @client.command() 装饰器的命令对我来说工作正常,但我尝试过的事件都没有工作.

I am trying to make a discord bot with the Discord.py library. The commands with the @client.command() decorator work fine for me, but none of the event ones that I tried work.


@client.event
async def on_member_join(member):
    channel = client.get_channel(ChannelId) #I did define channel Id in my code
    await channel.send("someone has joined")

@client.event
async def on_member_remove(member):
    print("Someone has left")

我希望这会输出到终端或我输入的频道 ID,但什么也没有出现,甚至没有错误消息.

I would expect this to output to the terminal or in the channel id I put in, but nothing appears, not even an error message.

*我用过客户端.对于所有功能.*我在 mac 上做这个.

*I used client. for all functions. *I am doing this on mac.

我不太确定它为什么起作用,我没有收到任何错误消息,而且我似乎找不到其他人遇到这个问题.

Im not quite sure why its working, I do not get any error messages, and I cant seem to find anyone else with this problem.

提前致谢

推荐答案

使用版本 >1.5.0 你可以这样做:

With version >1.5.0 you can do something like this:

import discord

intents = discord.Intents.default()
intents.members = True

client = discord.Client(intents=intents)

@client.event
async def on_member_join(member):
    await member.send("Welcome!")

这篇关于Discord.py on_member_join 不起作用,没有错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

在xarray中按单个维度的多个坐标分组
groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)...
2024-08-22 Python开发问题
15

Pandas中的GROUP BY AND SUM不丢失列
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)...
2024-08-22 Python开发问题
17

GROUP BY+新列+基于条件的前一行抓取值
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)...
2024-08-22 Python开发问题
18

PANDA中的Groupby算法和插值算法
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)...
2024-08-22 Python开发问题
11

PANAS-基于列对行进行分组,并将NaN替换为非空值
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)...
2024-08-22 Python开发问题
10

按10分钟间隔对 pandas 数据帧进行分组
Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)...
2024-08-22 Python开发问题
11