【问题标题】:How to make a discord bot respond to the user if they say a keyword in their message如果用户在消息中说出关键字,如何让不和谐机器人响应用户
【发布时间】:2019-05-22 09:09:03
【问题描述】:

所以我想做一个命令,当我说出一个已编程的关键字时,机器人可以响应句子中的那个单词,例如

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

【问题讨论】:

  • 这是关于不和谐机器人吗?
  • 是的,它涉及一个不和谐的机器人

标签: python-3.x discord.py


【解决方案1】:

提醒您必须使用python3.5。

安装discord后: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)

请注意,您还必须在 on_message 的末尾添加 process_commands

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-21
    • 2020-05-18
    • 2021-01-04
    • 1970-01-01
    • 2021-07-07
    • 2020-06-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多