如果用户在他们的消息中说出关键字,如何让不和谐机器人响应用户

问题描述 投票:0回答:1

所以我想做一个命令,当我说一个已编程的关键字时,机器人可以回答句子中的那个单词,就像

if message.content.upper().includes(‘keyword’)

python-3.x discord.py
1个回答
1
投票

提醒你必须在python3.5上。

安装不和之后:pip3 install --user discord.pygetting the token for your bot

from discord import Client

bot = Client()

# change keyword here
keyword = "RESPOND"

@bot.event
async def on_message(message):
      message_text = message.content.strip().upper()
      if keyword in message_text:
            # do something here, change to whatever you want
            await bot.send_message(message.channel, "'{}' was said".format(keyword))

bot.run("TOKEN")

如果你有一个使用commands的机器人,你可以像这样初始化它:

from discord.ext import commands
bot = commands.Bot(command_prefix=commands.when_mentioned)

请注意,您还必须在process_commands末尾包含on_message

© www.soinside.com 2019 - 2024. All rights reserved.