如何发送嵌入客户端准备好

时间:2020-03-27 05:41:38

标签: python discord.py

我正在用discord.py创建一个机器人。

机器人准备就绪后,我想将嵌入内容发送到特定的不和谐频道。为此,这是我的代码:

import discord

client = discord.Client()

logchannel = client.fetch_channel(692934456612487199)

@client.event
async def on_ready():
    print(f'Ticket Tool active as {client.user}')
    embed = discord.Embed(title="**Jokz' Ticket Tool**", color=0xff0000, description="Started Successfully!")
    embed.set_footer(text="JokzTickets | @jokztools",icon_url="https://pbs.twimg.com/profile_images/1243255945913872384/jOxyDffX_400x400.jpg")
    embed.set_thumbnail(url="https://gifimage.net/wp-content/uploads/2017/10/check-mark-animated-gif-12.gif")
    await logchannel.send(embed=embed)

client.run(key)

运行此命令时,出现以下错误:

PS C:\Users\jokzc\Desktop\jokzticketspy> py index.py
Ticket Tool active as Jokz' Tools#5577
Ignoring exception in on_ready
Traceback (most recent call last):
  File "C:\Users\jokzc\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 312, in _run_event
    await coro(*args, **kwargs)
  File "index.py", line 15, in on_ready
    await logchannel.send(embed=embed)
TypeError: send() takes no keyword arguments

格式化它的正确方法是什么?

2 个答案:

答案 0 :(得分:0)

所以我最终弄清楚了,如果我将功能从client.fetch_channel更改为client.get_channel,那么它就可以工作了,我需要将其放在实际的on_ready函数中!这样做的原因是,在客户端真正准备就绪之前,客户端无法获取或获取频道。

更正后的代码如下:

@client.event
async def on_ready():
    logchannel = client.get_channel(692934456612487199)
    print(f'Ticket Tool active as {client.user}')
    embed = discord.Embed(title="**Jokz' Ticket Tool**", color=0x00ff00, description="Started Successfully!")
    embed.set_footer(text="JokzTickets | @jokztools",icon_url="https://pbs.twimg.com/profile_images/1243255945913872384/jOxyDffX_400x400.jpg")
    embed.set_thumbnail(url="https://gifimage.net/wp-content/uploads/2017/10/check-mark-animated-gif-12.gif")
    await logchannel.send(embed=embed)

答案 1 :(得分:0)

@client.event
async def on_ready():
    channelid = client.get_channel(id)
    botname = client.user.name
    print('message ' + botname)
    embed = discord.Embed(title=f"Text", description="Text", color=discord.Color.red())
        
    embed.set_footer(text="Your text", icon_url="URL of icon")
    embed.set_thumbnail(url="Url")
    await channelid.send(embed=embed)