首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >嘿,谁能给我看看discord.py API上的代码吗?使用网站的api

嘿,谁能给我看看discord.py API上的代码吗?使用网站的api
EN

Stack Overflow用户
提问于 2020-07-02 00:47:09
回答 2查看 371关注 0票数 0

我试图创建一个堡垒之夜API,给我所有泄露的化妆品与一个不和谐的机器人,我只是不知道从哪里开始!有人能帮忙吗!谢谢你

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-07-02 04:13:58

下面是一个简单的机器人的例子,它重复了你说的话。

代码语言:javascript
运行
复制
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)
票数 0
EN

Stack Overflow用户

发布于 2020-07-02 03:28:12

下面是在Cog必需导入中使用api的示例:

代码语言:javascript
运行
复制
from discord.ext import commands
from discord import Embed, Color
from aiohttp import ClientSession
from ast import literal_eval

获取随机查克·诺里斯笑话的命令

代码语言:javascript
运行
复制
    @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端点并应用我上面所做的来获得您所需要的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62687325

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档