Discord BOT python, как отправить сообщение при указании c пользователь написал команду - PullRequest
0 голосов
/ 06 августа 2020

я хочу, чтобы мой Discord BOT делал что-то вроде этого:

Если я скажу «реагировать», BOT ответит

Если кто-то другой, кроме меня, скажет «реагировать», BOT не будет ответить

Я пробовал этот код ниже, но у меня он не работает

if message.author.id == ('<User ID here>') and message.content.lower() == 'react':

await message.channel.send('i am only react to my Master not others!')

Может, я что-то написал не так в коде? скажите, пожалуйста, это мне очень поможет!

Ответы [ 2 ]

1 голос
/ 06 августа 2020

Это должно делать именно то, что вы хотите:

@client.event
#We create an on message event
async def on_message(message):
     #We check if the the message that has been sent equals react
     if "react" in message.content:
          #We check that the person who sent the message is you
          if type(message.author) == discord.user.ClientUser:
             #Do something
          else:
             #Do something else
     else:
          pass
0 голосов
/ 07 августа 2020

Это моя ошибка я полагаю поэтому я писал так раньше

if message.author.id == ('<User ID here>') and message.content.lower() == 'react':

    await message.channel.send('i am only react to my Master not others!')

Я не должен ставить (скобки) после message.author.id, и это правильный

if message.author.id == <ID goes here> and message.content.lower() == 'react':
    await message.channel.send('reacted!')
...