小编Dom*_*nik的帖子

如何用Pillow绘制进度条?

我目前正在尝试根据计算的百分比绘制进度条。

但是,我无法以正确的格式显示它。

我将自己定位在这个网站的另一个答案(How do you make a Progress Bar and put it on an image? & Is it possible to add a blue bar using PIL or Pillow?

但要么是进度条太长而width限制不起作用,要么进度条显示没有进度。

示例1:

async def rank(self, ctx, member: discord.Member):
    member = ctx.author

    data = await database.find_user(collection_user, ctx.guild.id, ctx.author.id)
    already_earned = data["exp"]

    to_reach= ((50 * (data['lvl'] ** 2)) + (50 * (data['lvl'] - 1)))
    
    percentage = ((data["exp"] / next_level_xp ) * 100) # Get the percentage

    ## Rank card
    img …
Run Code Online (Sandbox Code Playgroud)

python python-imaging-library discord.py

7
推荐指数
1
解决办法
1354
查看次数

如何根据唯一频道名称或ID返回YouTube频道信息

@username我正在尝试编写一个简单的 Python 脚本,通过或搜索返回有关频道的一些信息UCrandomID123

我知道您可以使用以下端点来访问频道数据:https://www.googleapis.com/youtube/v3/channels

然而,我遇到了一些可能的限制和问题。某些频道的频道 URL 中可能没有自定义“名称”:

在此输入图像描述

在此输入图像描述

我查了一下问题并发现了多个解决该问题的帖子:

但这两种解决方案都相当陈旧,我想知道现在是否有更好的解决方案来解决这个问题?

我有以下代码:

async def get_channel_id(self, channel_input):
        api_url = f"https://www.googleapis.com/youtube/v3/channels"
        params = {
            'part': 'snippet',
            'key': DEVELOPER_KEY,
            'maxResults': 1
        }

        # Determine if the input is a channel ID or username
        if channel_input.startswith('UC'):
            # Channel ID provided
            params['id'] = channel_input
        else:
            # Assume it's a custom username
            params['forUsername'] = channel_input

        response = await self.make_api_request(api_url, params) # Just a function to make …
Run Code Online (Sandbox Code Playgroud)

python youtube-data-api

5
推荐指数
1
解决办法
460
查看次数

将按钮组件添加到消息 (discord.py)

在 discord 的 API 参考中看到这个(消息组件)后,我想知道是否有任何方法可以使用 python 来实现它?

我尝试制作一个 json 数组并将其传递到我的消息中,但无法使其工作。

我也尝试查看 python 的参考,但找不到任何东西。

这是我的代码

components= [
  {
    "type": 2,
    "label": "Clear les kick",
    "style": 4,
    "custom_id": "clear_kick_button"
  }
]
@slash.slash(name="kicked", description="Voir qui a été kick et combien de fois.", guild_ids=guild_id)
async def kicked(ctx):
  await ctx.send("test", components= components)
Run Code Online (Sandbox Code Playgroud)

如果你有任何信息,如果你分享它,谢谢你。

python api discord.py

1
推荐指数
1
解决办法
1万
查看次数