Python message.content discord bot

时间:2018-03-06 02:53:20

标签: python python-requests bots discord discord.py

我想要一个帮助,我试图让我的不和谐机器人在有人写一些单词时自动响应,问题是该命令只有在该单词是句子中写的第一件事时才有效。我希望我的机器人能够对这个消息作出回应,即使这个词在某个句子的中间。 我该怎么办?

2 个答案:

答案 0 :(得分:3)

Bot = commands.Bot(command_prefix="")

@Bot.event

async def on_message(message):

     if "not" in message.content:
           await Bot.send_message(message.channel, 'yes')

澄清一下 - message.content.startswith只会检查定义的字符/字符串是否在消息的开头,而message.content会扫描发送的整个消息。

答案 1 :(得分:0)

ma​​in.py:

import discord

client = discord.Client()

@client.event
async def on_message:
 if message.content.startswith(‘Exemple’):
   message.channel.send(‘this is an exemple’)

client.run(os.getenv(‘TOKEN’))

.env:

TOKEN=[paste the token of the bot here]