我正在尝试为Discord创建一个bot,每次我尝试使用以下代码将消息发送到指定的频道时,它不会给我任何错误,但会打印“无”,这是我在频道不存在时所期望的。我现在已经用多个公会/服务器和多个文本频道,以及运行相同代码的多台计算机尝试了这一点。在下面的代码中,我将channelID替换为int,int是channelID,将token替换为我的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")
bot确实具有管理权限,以及两个意向网关
似乎您正在尝试在实际运行bot之前调用bot的功能
尝试在
on_ready()
回调中添加代码,以确保仅在初始化bot本身之后才尝试获取通道您需要修改
与
相关问题 更多 >
编程相关推荐