F
F
frykktik2021-11-14 06:49:45
Python
frykktik, 2021-11-14 06:49:45

Can you check what is wrong here and why it does not work?

Check the code, it executes the first if and writes to the PM, but the 2 if does not work, it does not issue a role, and does not respond to this command at all.

@bot.event
async def on_message(m):
  if m.content == "Привет":
      await m.author.send("Как дела?")
      
  if m.guild is None and not m.author.bot:
        if m.content == "Хорошо":
            member = m.author
            role = discord.utils.get(member.guild.roles, id=908718776525135922)
            await member.add_roles(role)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-11-14
@frykktik

does not respond to this command at all

That's impossible.
Errors in the console?
You get a User object, not a Member, because the chat is private.
https://discordpy.readthedocs.io/en/stable/api.htm...
The Member object does not have a field with a server, so it also cannot be assigned a role, because it is not clear which server the role should be assigned to

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question