所以我想做一个命令,当我说一个已编程的关键字时,机器人可以回答句子中的那个单词,就像
if message.content.upper().includes(‘keyword’)
提醒你必须在python3.5上。
安装不和之后: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)
请注意,您还必须在process_commands
末尾包含on_message
。