V
V
VadnenGG2020-10-24 14:59:23
Python
VadnenGG, 2020-10-24 14:59:23

Why doesn't Heroku see the on_member_join event in discord.py?

Here is the code:

from discord.ext import commands
from discord.utils import get
import os
import discord
import asyncio

intents = discord.Intents.default()

ds = commands.Bot(command_prefix='!')
@ds.event
async def on_member_join(member, intents=intents):
    channel = ds.get_channel(713305916044214292)


    vk = get(ds.emojis, name='vk')
    twitch = get(ds.emojis, name='twitch')

    role = discord.utils.get(member.guild.roles, name="Без роли")
    await member.add_roles(role)


    await channel.send(f"Приветствую тебя, {member.mention} :wave:")
    emb = discord.Embed()
    emb.color = discord.Colour.gold()
    emb.add_field(name = "⁣⁣⁣ ", value = f"""**В первую очередь рекомендуем получить**
**роль для доступа ко всем каналам**
**:closed_lock_with_key:[Получить роль](https://discord.gg/Bv85HnT)**
**Для комфортного времяпрепровождения**
**рекомендуем озокомиться с**
**:clipboard:[Правилами Discord](https://discord.gg/YGXUGva)**
**Полезные ссылки:**
{vk}[Группа Вк](https://vk.com/diadem.mine)
{twitch}[Twitch](https://www.twitch.tv/d1adem_)""")
    emb.set_thumbnail(url = "https://images-ext-1.discordapp.net/external/1AXiajN3xjbjin6VR-J4QNOG4Gy4wPP-uabVCUGMAp0/https/media.discordapp.net/attachments/713367810985689110/714404218777239614/anim.gif")
    emb.set_author(name = """Добро пожаловать в  официальный Discord 
 канал проекта Diadem!""", icon_url=member.avatar_url)

    await channel.send(embed = emb)
token = os.environ.get("BOT_TOKEN")

ds.run(token)


When I run it on my computer everything works.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Nevzorov, 2020-10-24
@VadnenGG

Because it on_member_joinrequires the "members" intent: https://discordpy.readthedocs.io/en/stable/api.htm...
2Fvc1cT.png
And the intents argument is not passed to the listener, but to the bot's constructor.

intents = discord.Intents.default()
intents.members = True
# либо «intents = discord.Intents.all()» если оба intents доступны

ds = commands.Bot(command_prefix='!', intents=intents)


@ds.event
async def on_member_join(member):
    ...

Before enabling intent in code, make sure it is enabled in the app bar in Discord:
48C5rAj.png
Otherwise, you will get an exception when starting the bot

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question