【发布时间】:2020-05-31 09:20:40
【问题描述】:
我一直在做很多工作,通过 javascript 和 discord.js 使用 discord api 创建不和谐机器人。
我正在尝试使用通过 discord.py 的 discord api 和通过 requests.py 的请求使用 python 创建我的第一个 discord 机器人。
我的目标是检查网站上的状态代码,当发送包含“状态代码”的消息时,它将在嵌入中回复该站点的状态代码。
这是我的代码:
import discord
import requests
r = requests.get('redactedurl')
test = r.status_code
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as {0}!'.format(self.user))
async def on_message(self, message):
if (message.channel.id == redacted):
if "status code" in message.content:
print('Message from {0.author}: {0.content}'.format(message))
embed = discord.Embed(color=0x00ff00)
embed.title = "test"
embed.description = '**Status Code:** {r.status_code}'
await message.channel.send(embed=embed)
client = MyClient()
client.run('redacted')
以下是我希望任何人都可以回答以帮助我的问题列表:)
-
正如您在此处看到的:https://gyazo.com/f6ae7082486cade72389534a05655fec,这只是在嵌入中发送“{r.status_code}”,而不是实际的状态代码,我做错了什么?
-
当我在大括号中看到 0 时,这是什么意思。例如,有人可以向我解释“('以 {0} 身份登录!'.format(self.user))”吗?由于我是 python 和 discord.py 的新手,所以我对整行感到困惑。我知道结果是什么,但请原谅我的无知,这一切都是必要的吗?
-
在“send(embed=embed)”中,为什么不能直接放send(embed)?
-
最后,我还能做些什么来改进代码吗?
如果您能提供帮助,非常感谢!
【问题讨论】:
标签: python discord discord.py