如何通过Discord机器人(带有python)发送嵌入内容?

编程入门 行业动态 更新时间:2024-10-11 07:35:08
本文介绍了如何通过Discord机器人(带有python)发送嵌入内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在研究一个新的Discord机器人。

I've been working a new Discord bot.

我学到了一些东西,现在,我想做些事情更多自定义。

I've learnt a few stuff,and, now, I'd like to make the things a little more custom.

我一直在尝试使漫游器发送嵌入消息,而不是发送普通消息。

I've been trying to make the bot send embeds, instead, of a common message.

embed=discord.Embed(title="Tile", description="Desc", color=0x00ff00) embed.add_field(name="Fiel1", value="hi", inline=False) embed.add_field(name="Field2", value="hi2", inline=False) await self.bot.say(embed=embed)

在执行此代码时,我收到以下错误:嵌入不是模块 discord的有效成员。所有网站,请向我显示此代码,并且我不知道发送嵌入的其他方法。

When executing this code, I get the error that 'Embed' is not a valid member of the module 'discord'. All websites, show me this code, and I have no idea of any other way to send a embed.

推荐答案

要获取它工作,我将您的send_message行更改为 await message.channel.send(embed = embed)

To get it to work I changed your send_message line to await message.channel.send(embed=embed)

这是一个完整的示例代码演示了它们如何适合:

Here is a full example bit of code to show how it all fits:

@client.event async def on_message(message): if message.content.startswith('!hello'): embedVar = discord.Embed(title="Title", description="Desc", color=0x00ff00) embedVar.add_field(name="Field1", value="hi", inline=False) embedVar.add_field(name="Field2", value="hi2", inline=False) await message.channel.send(embed=embedVar)

我使用discord.py文档来帮助找到它。 discordpy.readthedocs.io/ zh_cn / latest / api.html#discord.TextChannel.send 来确定send方法的布局。

I used the discord.py docs to help find this. discordpy.readthedocs.io/en/latest/api.html#discord.TextChannel.send for the layout of the send method.

discordpy.readthedocs.io/en/latest/api.html#embed (针对Embed类)。

discordpy.readthedocs.io/en/latest/api.html#embed for the Embed class.

1.0之前的版本:如果您使用的是1.0之前的版本,请使用 await client.send_message(message.channel,embed = embed)方法。

Before version 1.0: If you're using a version before 1.0, use the method await client.send_message(message.channel, embed=embed) instead.

更多推荐

如何通过Discord机器人(带有python)发送嵌入内容?

本文发布于:2023-11-23 13:08:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621556.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:机器人   内容   Discord   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!