我在下面有一个示例代码块,我正在尝试运行该代码块以向特定频道发送消息。当我运行它时,我收到此错误:AttributeError: 'NoneType' object has no attribute 'send'。我知道频道 ID 很好。这很简单,但我知道 discord.py 所以我可能会忽略一些东西
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)
答案 0 :(得分:0)
你可以试试这个
Channel=‘#channelID’
Await channel(‘#your message’)
答案 1 :(得分:0)
你可以试试这个:
@client.event
async def on_ready():
# get channel by ID and save it in the variable "channel"
channel = await client.get_channel(811074101505425418)
# send your message to the channel
await channel.send('bot is ready')