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