ran*_*der 3 python discord discord.py
我正在尝试为 Discord 制作一个机器人,每次我尝试使用以下代码向指定频道发送消息时,它不会给我任何错误,但会打印“None”,这是我期望的该频道不存在。我现在已经在多个公会/服务器和多个文本通道以及运行相同代码的多台计算机上进行了尝试。在下面的代码中,我将channelID替换为int(即channelID),将token替换为我的令牌(字符串)。
import discord
from discord.ext import commands
intents = discord.Intents.all()
client = commands.Bot(command_prefix = 'bday ', intents = intents)
channel = client.get_channel(channelID)
print(channel)
client.run("token")
Run Code Online (Sandbox Code Playgroud)
该机器人确实具有管理员权限,以及两个意图网关
小智 7
看起来您正在尝试在实际运行机器人之前调用机器人的功能。
尝试在回调中添加代码,on_ready()以确保您仅在初始化机器人本身后才尝试获取频道。
import discord
from discord.ext import commands
intents = discord.Intents.all()
client = commands.Bot(command_prefix = 'bday ', intents = intents)
@client.event
async def on_ready():
channel = client.get_channel(channelID)
print(channel)
client.run("token")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9627 次 |
| 最近记录: |