如何使用 python bot 发送随机嵌入图像

时间:2021-01-23 23:35:07

标签: python discord discord.py

这是我使用的:

int

我在 YouTube 上使用教程并复制了代码但它仍然不起作用,我放置了一个单独的文件来获取链接但它仍然不起作用,我也在尝试嵌入它们这有点复杂,但我仍然需要帮助。

1 个答案:

答案 0 :(得分:0)

一种简单易行的方法,它会从“images”数组中随机选择一个图片链接,并将其显示为嵌入中的图片网址。

using Prism.Commands;
using Prism.Mvvm;
using System;

namespace LineGridViewCh4.ViewModels
{
    public class LineGridControlViewModel : BindableBase
    {
        public DelegateCommand<string> ChangeLinesCommand { get; set; }

        public LineGridControlViewModel()
        {
            ChangeLinesCommand = new DelegateCommand<string>(ChangeLines);
        }

        private int lines;
        public int Lines
        {
            get { return lines; }
            set { SetProperty(ref lines, value); }
        }
        public void ChangeLines(string numberOfLines)
        {
            Lines = Convert.ToInt32(numberOfLines);
        }
    }
}

更高级,您可以使用 api 或 json 文件,它们允许您从其他在线资源中获取图像,例如:

images = ['https://i.redd.it/123123.jpg', 'etc', 'image link', 'etc', 'image link', 'etc']

@client.command()
async def image(ctx):
    embed = discord.Embed(
    title="Random Image",
    colour=discord.Colour(0x7289DA),
    description=f"Random Image",
    timestamp=datetime.datetime.utcfromtimestamp(1580842764)
    )
    embed.set_image(url=(random.choice(images)))


    await ctx.send(embed = embed)

但把它留给你,希望这对你有帮助