不协调Python bot不发送消息

2024-04-26 14:19:14 发布

您现在位置:Python中文网/ 问答频道 /正文

请不要说“已经回答”,因为我尝试了一切,包括这里的所有相关帖子,显然,我正在阅读api文档

完全错误为:

正在忽略on_ready中的异常 回溯(最近一次呼叫最后一次): 文件“/usr/local/lib/python3.8/dist-packages/discord/client.py”,第312行,在运行事件中 等待coro(*args,**kwargs) 文件“embbed_shop.py”,第26行,on_ready 等待通道。发送消息(嵌入=嵌入) AttributeError:“非类型”对象没有“发送消息”属性

这是我的完整代码(令牌除外):

import discord
from discord.ext import commands
import datetime
import asyncio
import time

from urllib import parse, request
import re

bot = discord.Client()

@bot.event
async def on_ready():
    embed = discord.Embed(title="Le SHOP de POIDSPLUME", colour=discord.Colour(0xff9e26), url="https://discordapp.com", description="```yaml\n \t\t\t\t CASSIMON vs ENDER```", timestamp=datetime.datetime.utcfromtimestamp(1593927421))

    embed.set_image(url="https://vignette.wikia.nocookie.net/bokunoheroacademia/images/d/d8/Class_1-A_vs._Mirio_Togata_Anime.png/revision/latest?cb=20181001113201")
    embed.set_thumbnail(url="https://i.pinimg.com/564x/d5/76/60/d576605d7afc2387757862d9916ea911.jpg")
    embed.set_author(name="Poidsplume SHOP", icon_url="https://cdn.discordapp.com/embed/avatars/0.png")
    embed.set_footer(text="Powered by @Poidsplume (La Banque)", icon_url="https://i.pinimg.com/564x/d5/76/60/d576605d7afc2387757862d9916ea911.jpg")

    embed.add_field(name=" __Achats Cassimon__ ", value="- 1000 pokédollars :dollar: =  200 <:perfectprism:726002243677192283> __ou__ 80 <:Antimater:726002322127454227> \n-1 Pokémon SH qui méga ou giga  = 2k <:Antimater:726002322127454227> ou équivalent ", inline=True)
    embed.add_field(name="__Ventes Cassimon__ ", value="Les pokémons en vente sont tous à __1500__ pokédollars :dollar: : \n\n x1 Mouscoto <:mouscoto:729241671899938826> \n x1 Ho-oh <:ho_oh_1:729240842518134795> \n x1 Régirock <:regirock:729241757803348000> \n x1 Necrozma Crinière du couchant <:necrozma_criniere:729241703273463830> \n\n\nx1 Hélionceau SH <:helionceau:729242441206726738>", inline=True)
    embed.add_field(name=".", value="```yaml\n \t\t\t\tENDER vs ENDER```")
    embed.add_field(name=".", value="A VENIR[]")
    channel = bot.get_channel(712559462262767617)
    await channel.send_message(embed=embed)

bot.run("TOKEN") ```

Regards,

Tags: namehttpsimportcomaddurlfieldvalue
2条回答
  1. 从以下位置删除引号:

channel = bot.get_channel('712559462262767617')

channel = bot.get_channel(712559462262767617)


  1. send_message更改为send

await channel.send(embed=embed)


请告诉我这是否有效。 似乎您正在使用旧版本的discord.py


我从:Trying to send a message to a specific channel using Discord.py rewrite and it isn't working得到了这个答案

这个API参考可能更有用:https://discordpy.readthedocs.io/en/latest/api.html#textchannel

您必须使用send而不是我上面链接的文档中定义的send_message

embed = discord.Embed(title="Hi!")

channel = bot.get_channel(712559462262767617)
await channel.send(embed=embed)

在discord.py的新版本中,您必须了解一些变化 比如说,

  • 雪花不再是字符串,它们现在是整数
  • send_message变成了send
  • 服务器现在是公会

请毫不犹豫地查看此链接以获取完整的更改列表: https://discordpy.readthedocs.io/en/latest/migrating.html

相关问题 更多 >