【发布时间】:2019-01-17 06:52:53
【问题描述】:
import random
import asyncio
import aiohttp
import discord
import json
from discord import Game
from discord.ext.commands import Bot
TOKEN = ''
client = discord.Client()
botnum = 0
@client.event
async def on_ready():
print('Online and Ready to Play!')
print(client.user.name)
print(client.user.id)
await client.change_presence(game=discord.Game(name="With Emotions"))
print('------')
@client.event
async def on_message(message):
global botnum
# we do not want the bot to reply to itself
if message.author == client.user:
return
elif message.content.startswith('Peribot'): ### Updated to elif which is more acceptable
msg = "I'm Busy! D:<".format(message)
await client.send_message(message.channel, msg)
elif botnum == 20: ### forgot a ":" and Updated to elif which is more acceptable
msg = "You Clods are so loud!".format(message)
await client.send_message(message.channel, msg)
botnum = 0 ### you were comparing and not setting botnum to 0
else:
botnum += 1 ### This will add 1 to the preexisting number of botnum
elif message.content.startswith('info'): ### Updated to elif which is more acceptable
msg = "Created by Popleoma with the intent of being a fun bot. Commands are Peribot, info, and more to come!".format(message)
await client.send_message(message.channel, msg)
client.run("")
每当我添加最后一个 elif 语句时,它都会连接到前一个 else 语句。我尝试在它们之间添加输入,但它一直在连接。这是我的文本编辑器输入的 https://imgur.com/a/EwPziWb 。我需要一种不连接的方法,因为当它连接时它不会运行我的代码,它只会使 python 编译器崩溃。
【问题讨论】:
-
“连接”是什么意思?为什么
else后面有elif?elif应该是什么的一部分? -
缩进在我看来很可疑。它真的运行了吗?
-
所有 elif 部分都错误地缩进到最后。
-
嗯,看看您的编辑器屏幕截图,我认为“连接”只是代码编辑器试图理解您的陈述。最后的 elif 看起来是一个孤儿,实际上它与任何东西都没有联系。应该是一个简单的If吗?
-
或者也许最后一个 elif 应该在 else 之前而不是在它之后?
标签: python discord discord.py