【发布时间】:2021-04-22 07:38:16
【问题描述】:
我正在尝试创建一个公告功能,它将必要的嵌入发送到我指定的频道中。我已经添加了必须发送的文本,但现在我希望它也包含图像。
我无法在嵌入中发送图片链接,因为它们不起作用。
我想发送另一个包含图片链接的参数并将其单独发送到聊天中。我试过了,但它只适用于一张图片。但是当我们想再输入一个时,它就行不通了。我正在尝试了解如何做到这一点。
以下是我正在处理的命令的代码。
@nd.command()
async def announce(ctx, channel, *, message):
townannouncerole = discord.utils.get(ctx.guild.roles, id=834684222441521193)
townannouncementchannel = nd.get_channel(834675349409234974)
if str(channel.lower()) == 'town':
if townannouncerole in ctx.author.roles:
townannouncementembed = discord.Embed(title="Town Announcement", description=message, color=discord.Colour.random())
townannouncementembed.set_author(name=ctx.author)
townannouncementembed.set_footer(text=datetime.datetime.now())
await townannouncementchannel.send(embed=townannouncementembed)
else:
await ctx.channel.send(f"Hi {ctx.author.mention}, you lack necessary permissions for this command!")
这是我用来发送单个图像的代码,它运行良好。
@nd.command()
async def announce(ctx, channel, images, *, message):
townannouncerole = discord.utils.get(ctx.guild.roles, id=834684222441521193)
townannouncementchannel = nd.get_channel(834675349409234974)
if str(channel.lower()) == 'town':
if townannouncerole in ctx.author.roles:
townannouncementembed = discord.Embed(title="Town Announcement", description=message, color=discord.Colour.random())
townannouncementembed.set_author(name=ctx.author)
townannouncementembed.set_footer(text=datetime.datetime.now())
await townannouncementchannel.send(embed=townannouncementembed)
await townannouncementchannel.send(images)
else:
await ctx.channel.send(f"Hi {ctx.author.mention}, you lack necessary permissions for this command!")
现在的问题是我无法理解 如何通过添加另一个多字参数(如 message 将包含其后的所有文本)将多个链接发送到聊天中。 不必按顺序保留参数。你可以用任何你想要的方式洗牌,解释和解决。
谢谢! :)
【问题讨论】:
标签: python python-3.x discord discord.py