【发布时间】:2021-06-06 19:43:10
【问题描述】:
我最近开始编写代码,并决定制作一个 Discord 机器人是一种很好、有趣的学习方式。所以我做了一些编码,从 Youtube 视频中学习,一切都很顺利,但现在我的代码都没有工作,机器人基本上没用。有人可以看看这段代码并告诉我是什么问题
import discord
import os
import requests
import json
import random
client = discord.Client()
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('Hello'):
await message.channel.send('Hi!')
client.run(os.getenv('TOKEN'))
sad_words = ["sad","alone","scared","depressed","SAD","Sad"]
starter_encouragements = [
"You got this. I know you do ????",
"I know it's hard, but you'll get through this :)",
]
def get_quote():
response = requests.get("https://zenquotes.io/api/random")
json_data = json.loads(response.text)
quote = json_data[0]['q'] + " -" + json_data[0]['a']
return(quote)
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
msg = message.content
if message.content.startswith('inspire'):
quote = get_quote()
await message.channel.send(quote)
if any(word in msg for word in sad_words):
await message.channel.send(random.choice(starter_encouragements))
client.run(os.getenv('TOKEN'))
非常感谢
【问题讨论】:
-
我不想粗鲁,但正确的术语是
code而不是codes,在编程上下文中的代码被认为是不可数名词,例如sand或water.你不会说I have some sands吧?这里也一样。