Discord Python机器人未发送消息 [英] Discord Python bot not sending message

查看:94
本文介绍了Discord Python机器人未发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请不要说已经回答",因为我尝试了一切,包括此处的所有相关帖子,而且显然是在阅读api文档.

Please don't say "Already answered", cause I tried EVERYTHING, including all related posts here and obviously, reading the api doc.

完全错误是:

忽略on_ready中的异常追溯(最近一次通话):_run_event中的文件"/usr/local/lib/python3.8/dist-packages/discord/client.py",第312行等待科罗(* args,** kwargs)在on_ready中,文件"embbed_shop.py",第26行等待channel.send_message(embed = embed)AttributeError:"NoneType"对象没有属性"send_message"

Ignoring exception in on_ready Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/discord/client.py", line 312, in _run_event await coro(*args, **kwargs) File "embbed_shop.py", line 26, in on_ready await channel.send_message(embed=embed) AttributeError: 'NoneType' object has no attribute 'send_message'

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

Here is my complete code (except token):

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,

推荐答案

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

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

You have to use send instead of send_message as defined in the documentation that I linked above

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

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

discord.py的新版本中,您需要了解一些更改.
例如,

There a couple of changes you have to understand in the new version of discord.py
For instance,

  • 雪花不再是字符串,现在是整数
  • send_message 变为 send
  • 服务器现在为公会
  • Snowflakes are no longer strings, they are integers now
  • send_message became send
  • Server is now Guild

请随时检查此链接以获取完整的更改列表: https://discordpy.readthedocs.io/en/latest/migrating.html

Don't hesitate to check this link for a complete list of changes: https://discordpy.readthedocs.io/en/latest/migrating.html

这篇关于Discord Python机器人未发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆