【发布时间】:2019-05-22 09:09:03
【问题描述】:
所以我想做一个命令,当我说出一个已编程的关键字时,机器人可以响应句子中的那个单词,例如
if message.content.upper().includes(‘keyword’)
【问题讨论】:
-
这是关于不和谐机器人吗?
-
是的,它涉及一个不和谐的机器人
标签: python-3.x discord.py
所以我想做一个命令,当我说出一个已编程的关键字时,机器人可以响应句子中的那个单词,例如
if message.content.upper().includes(‘keyword’)
【问题讨论】:
标签: python-3.x discord.py
提醒您必须使用python3.5。
安装discord后:pip3 install --user discord.py和getting 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。
【讨论】: