简体   繁体   English

如何让 discord 机器人在 python 的嵌入中发送随机消息

[英]How do I get a discord bot to send a random message inside an embed in python

So I wanted to use a command that puts a random message inside of an embed that also has a random gif attached to it, here is the code I'm using:所以我想使用一个命令,将随机消息放入一个嵌入中,该嵌入还附有一个随机 gif,这是我正在使用的代码:

roastgifs = [
'https://tenor.com/view/roasted-oh-shookt-gif-8269968'
]


@client.command(aliases=['Roast']) 
async def roast(ctx, member : discord.Member):
    global roasting
    global sus
    
    roasting = [line.strip() for line in open('jokes.txt')]
    sus = random.choice(roasting)
    
    embed=discord.Embed(title=f"{ctx.author.mention} roasts {member.mention}\n\"" + sus + "\"")
    roastgif=random.choice(roastgifs)
    embed.set_image(url=roastgif)
    embed.set_footer("footer")
    await ctx.send(embed=embed)

I can't find that many tutorials on yt and Google and even then they're probably js and not py so I resorted to coming here again.我在 yt 和 Google 上找不到那么多教程,即便如此,它们可能是 js 而不是 py,所以我再次求助于这里。

Also I would greatly appreciate how to make the bot ping someone with an ID if that's alright.另外,如果可以的话,我将非常感谢如何使机器人 ping 具有 ID 的人。

Embed.set_footer takes only keyword arguments, and you're passing a positional argument Embed.set_footer只接受关键字 arguments,并且您正在传递一个位置参数

embed.set_footer(text="Footer")

Also a few things:还有几点:

  1. You cannot ping in the embed title/footer (and somewhere else too, don't remember where atm)您无法 ping 嵌入标题/页脚(以及其他地方,不记得 atm 位置)
  2. The gif won't load. gif不会加载。 You only can add pictures in Embed.set_image您只能在Embed.set_image中添加图片

Reference:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 python 机器人发送随机嵌入图像 - How do I send random embed images with a python bot 使用Discord机器人,如何从另一个机器人获取嵌入消息的字符串 - Using a Discord bot, how do I get a string of an embed message from another bot 在 Python 中编程 Discord 机器人 - 如何使嵌入具有随机颜色? - Programming a Discord bot in Python- How do I make an embed have a random color? 在 Python 中编程 Discord 机器人 - 如何让机器人从 subreddit 发送随机文本组? - Programming a Discord bot in Python- How do I make the bot send a random group of text from a subreddit? 如何使用 python 通过我的 Discord 机器人发送嵌入? - How can I send an embed via my Discord bot, with python? 我绝对不能让我的机器人在 python 中发送嵌入消息 - I absolutely cannot get my bot to send a embed message in python 如何嵌入响应? Discord 机器人 Python - How do I embed a response? Discord Bot Python 如何从文件中获取随机行并将其作为 discord 机器人发送? - How do I get a random line from a file and send it as a discord bot? 我在 python 中按下反应后,如何让我的 discord 机器人发送消息? - How can i get my discord bot to send a message after i press a reaction in python? 如何使用 python discord 向机器人所在的每个服务器发送消息 - How can I send a message to every server the bot is in with python discord
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM