如何通过我的 Discord 机器人发送嵌入,使用 python?

时间:2023-05-13
本文介绍了如何通过我的 Discord 机器人发送嵌入,使用 python?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我一直在开发一个新的 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)

执行此代码时,我收到嵌入"不是模块不和谐"模块的有效成员的错误.所有网站,给我看这段代码,我不知道有什么其他的方式来发送嵌入.

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 行改为等待 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 文档来帮助找到它.https://discordpy.readthedocs.io/en/latest/api.html#discord.TextChannel.send 用于发送方法的布局.

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

https://discordpy.readthedocs.io/en/latest/api.html#embed 用于 Embed 类.

https://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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:Discord.py 错误:TypeError:__new__() 得到了意外的关键字参数“deny_new" 下一篇:带有 async def 的 Python [无效语法]

相关文章