Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Discord.py发送消息_Python_Discord.py - Fatal编程技术网

Python Discord.py发送消息

Python Discord.py发送消息,python,discord.py,Python,Discord.py,下面有一个示例代码块,我正试图运行该代码块向特定通道发送消息。当我运行它时,我得到以下错误:AttributeError:'NoneType'对象没有属性'send'。我知道频道id很好。这很简单,但我知道我会不和谐,所以我可能忽略了一些东西 import discord from dotenv import load_dotenv load_dotenv() TOKEN = os.getenv('DISCORD_TOKEN') GUILD = os.getenv('DISCORD_GUILD

下面有一个示例代码块,我正试图运行该代码块向特定通道发送消息。当我运行它时,我得到以下错误:AttributeError:'NoneType'对象没有属性'send'。我知道频道id很好。这很简单,但我知道我会不和谐,所以我可能忽略了一些东西

import discord
from dotenv import load_dotenv

load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD = os.getenv('DISCORD_GUILD')

intents = discord.Intents(guild_messages=True)
client = discord.Client(intents=intents)

@client.event
async def on_ready():
    await client.get_channel(811074101505425418).send("bot is online")

client.run(TOKEN)
你可以试试这个

Channel=‘#channelID’
Await channel(‘#your message’)

您可以尝试一下:

@client.event
_ready()上的异步定义:
#按ID获取通道并将其保存在变量“通道”中
通道=等待客户端。获取_通道(811074101505425418)
#将您的信息发送到频道
等待channel.send('机器人已准备就绪')

尝试
client.channel.send(“机器人处于联机状态”)
@Goion AttributeError:“客户端”对象没有属性“频道”是我要获取的内容重新检查您的令牌并检查您是否具有正确的权限。似乎无法进行身份验证或验证something@Goion我踢了机器人,重拨了开发者页面上的权限,但我仍然没有得到任何运气。。。对于如此直接的东西来说似乎真的很奇怪,
打印(client.user.name)
打印任何东西吗?