Запретить автору сообщения упоминать себя командой Discord.py

1

Пытаясь помешать пользователю упоминать себя, когда они используют команду rob. Я пробовал, if message.author == user.mention но он не работает.

   if message.content.startswith('!rob'):
        try:
            if message.author == user.mention:
                 await client.send_message(message.channel, "{} you cant rob yourself! ".format(message.author.mention))
        except:
            pass
        else:
             if get_dollars(message.author) < 0:
                await client.send_message(message.channel, "{} you can't even afford a gun!".format(message.author.mention))
        finally:
            for user in message.mentions:
                if (get_dollars(user)) < 25:
                    await client.send_message(message.channel, "{} is too broke to rob ".format(user.mention))
                elif steal == 1:
                    print("{} catches {} slippin and sticks them up for ${} ".format(message.author.mention, user.mention, stealdollars))
                    await client.send_message(message.channel, "{} catches {} slippin and sticks them up for ${} ".format(message.author.mention, user.mention, stealdollars))
                    remove_dollars(user, stealdollars)
                    add_dollars(message.author, stealdollars)
                elif steal == 2:
                    print("{} gets arrested trying to rob {} and has to post $250 bail ".format(message.author.mention, user.mention))
                    await client.send_message(message.channel, "{} gets arrested trying to rob {} and has to post $250 bail ".format(message.author.mention, user.mention))
                    remove_dollars(message.author, 250)
                elif steal >= 3:
                    print("{} kicks {} door down but doesn't find any cash ".format(message.author.mention, user.mention))
                    await client.send_message(message.channel, "{} kicks {} door down but doesn't find any cash ".format(message.author.mention, user.mention))
Теги:
python-3.x
discord
discord.py

2 ответа

2
Лучший ответ

Вы можете сделать что-то вроде

if message.author in message.mentions:
  • 0
    Спасибо, это исправило вопрос!
2

message.author - это discord.Member, user.mention нет.

Возможно, попробуйте что-то вроде:

if message.author.id == user.id: # User IDs don't change.
    await client.send_message(ctx.message.channel, "You cannot rob yourself")

Я надеюсь, что это помогло

  • 0
    Спасибо за предложение! Я попробовал это, но это позволило ему пройти и не отправило сообщение каналу, которому я хотел это. Я также попробовал message.author.id == user.mention.id и он тоже не отправил сообщение.
  • 0
    Извините за это, я привык переписывать сейчас, Это была ошибка с моей стороны. Забыл добавить аргумент канала, парень.
Показать ещё 1 комментарий

Ещё вопросы

Сообщество Overcoder
Наверх
Меню