discord.py:为什么我的加入消息不起作用? [英] discord.py: Why isn't my join message working?

查看:47
本文介绍了discord.py:为什么我的加入消息不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑为什么我的加入消息不起作用!我已经安装了discord.py库,我真的很困惑!我在它下面有其他代码,但是它不会影响上面的代码.

 导入不和谐客户端= discord.Client()@ client.event异步def on_ready():print('我们已经以{0.user}的身份登录'.format(client))@ client.event异步def on_member_join(成员):打印(玩家已加入")频道=等待client.fetch_channel(800395922764070942)等待channel.send(f'{member}已加入!')@ client.event异步def on_message(message):如果message.author == client.user:返回如果message.content.startswith('!loser'):等待message.channel.send('你好,输家!很高兴认识你.')elif message.content.startswith('!bruh'):等待message.channel.send('BRUHHHHHHHHHHHHHHHH !!!!')client.run(我的令牌在哪里") 

已编辑以显示完整代码.(对不起,这是愚蠢的事情,它们运行得很好,但我只想测试一下.)

解决方案

由于discord.py(1.5.0)的最新更改,您现在需要使用Intent.意图可以跟踪发生的事情.

首先,您需要在

然后在代码中,您需要在顶部添加它:

  intents = discord.Intents.default()intents.members =真客户= discord.Client(intents = intents) 

您现在将能够接收诸如 on_member_join 之类的事件.

I am stumped on why my join message isn't working! I have the discord.py library installed, and I am really confused! I have other code below it, but it shouldn't effect the above.

import discord

client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_member_join(member):
    print("Player has joined")
    channel = await client.fetch_channel(800395922764070942)
    await channel.send(f'{member} has joined!')
    
@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('!loser'):
        await message.channel.send('Hello loser! Nice to meet you.')
    elif message.content.startswith('!bruh'):
        await message.channel.send('BRUHHHHHHHHHHHHHHH!!!!')

client.run("Where my token is")

Edited to show entire code. (Sorry for the stupid bruh things, they run perfectly but I just wanted to test some things..)

解决方案

Due to recent changes in discord.py (1.5.0) you now need to use intents. Intents enable to track things that happen.

First you need to enable it on the developer portal (where you created your bot). When you're there, select your application, go to the bot section, scroll down and tick the box.

Then in your code you need to add this at the top :

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

client = discord.Client(intents=intents)

You will now be able to receive events like on_member_join.

这篇关于discord.py:为什么我的加入消息不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆