我试图创建一个堡垒之夜API,给我所有泄露的化妆品与一个不和谐的机器人,我只是不知道从哪里开始!有人能帮忙吗!谢谢你
发布于 2020-07-02 04:13:58
下面是一个简单的机器人的例子,它重复了你说的话。
import discord # importing the discord.py library
from discord.ext import commands # extension of said library
# This defines the bot's command prefix and if the commands are case insensitive
bot = commands.Bot(command_prefix='-', case_insensitive='True')
@bot.event =
async def on_ready():
```
This is an event that prints to the console that the bot is online and ready to go.
```
print('Bot is ready!') # prints to console that the bot is ready.
@bot.command()
async def echo(ctx, *, msg):
```
This is a command that repeats what you say. Echo is the name. *, msg means that all the words listed after the command are repeated
```
await ctx.message.delete() # delete the command message the the user said
await ctx.send(msg) # say whatever the user wanted to say.
# bot token here. found in the discord developer website
bot.run(YOUR BOT'S TOKEN GOES HERE)
发布于 2020-07-02 03:28:12
下面是在Cog
必需导入中使用api的示例:
from discord.ext import commands
from discord import Embed, Color
from aiohttp import ClientSession
from ast import literal_eval
获取随机查克·诺里斯笑话的命令
@commands.command()
async def chuck(self, ctx):
ad = Embed(color=Color.dark_gold())
base = "https://api.chucknorris.io/jokes/random"
async with ClientSession() as session:
data = await get(session, base)
data = literal_eval(data)
ad.set_author(name="Chuck Norris",
icon_url="https://i.ibb.co/swZqcK7/norris.gif",
url=data['url'])
ad.description = data['value']
return await ctx.send(embed=ad)
如果您从堡垒之夜那里获得信息,很可能他们已经在PyPi上拥有一个Python,或者您可以查找一个JSON端点并应用我上面所做的来获得您所需要的。
https://stackoverflow.com/questions/62687325
复制相似问题