因此,在使用if message.content.startswith((prefix + smalltalk0[0]) or (prefix + smalltalk0[1]) or (prefix + smalltalk0[2])):
时,这里似乎有问题,而if语句似乎只在第一个条件下工作:(prefix + smalltalk0[0])
,(我在其中写“ sab hi”,它会做出响应。但是由于某种原因,它不会响应“ sab hello”或“ sab hey”。)
有人可以在这里帮助我吗,我猜我的错误与使用倍数或语句有关,但请更正其他可能出错的地方,非常感谢!
这是我所有的代码(是的,我确实知道help命令还没有完全完成并且可以运行,大声笑,我只是被位于代码末尾的一小段讨论区所困扰!):
import discord
import random
import asyncio
TOKEN = '*insert token here'
client = discord.Client()
prefix = ("sab ")
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith(prefix + "help"):
_help = "{0.author.mention}...Check your PMs".format(message)
await message.channel.send("Prefix: 'sab '(yes,including the space after)\nGENERAL COMMANDS\n------------\n'help': Sends some stuff on how to use the bot.\n'tell a joke': Tells a rubbish joke...".format(author))
await message.channel.send(_help)
if message.content.startswith(prefix + "tell a joke"):
joke = ["What did the grape do when he got stepped on?","Why couldnt the bicycle stand up by itself?","How did the frog die?","What do you call a can opener that doesn't work?","Why does he want his job to be cleaning mirrors?","What does a clock do when it's hungry?","Why do sea-gulls fly over the sea?"]
answer = ["He let out a little wine!","Because it's two-tired!","He Kermit suicide!","A can't opener!","Because it's something he can really see himself doing!","It goes back four seconds!","Because if they flew over the bay they would be bagels!"]
y = [0,1,2,3,4,5,6]
x = random.choice(y)
jokenum = joke[x]
answernum = answer[x]
msg = jokenum.format(message)
msg2 = answernum.format(message)
await asyncio.sleep(1)
await message.channel.send(msg)
await asyncio.sleep(4)
await message.channel.send(msg2)
colours = ["blue","orange","yellow","red","green" ]
p = [0,4]
z = random.choice(p)
colournum = colours[z]
colourcorrect = str(colournum)
if message.content.startswith(prefix + "play eye spy"):
await message.channel.send("Eye spy with my little eyes,a certain colour!(Guess it!)")
if colourcorrect in message.content:
await message.channel.send("Correct," + colourcorrect + "!")
smalltalk0 = ["hi","hello","hey"]
q = [0,2]
s = random.choice(q)
smalltalk = smalltalk0[s]
if message.content.startswith((prefix + smalltalk0[0]) or (prefix + smalltalk0[1]) or (prefix + smalltalk0[2])):
await message.channel.send(smalltalk)
@client.event
async def on_ready():
print('Sabios ready')
client.run(TOKEN)