我正在制作一个 Discord 机器人来处理公告命令。当使用该命令时,我希望机器人在特定通道中发送一条消息,并向用户发送一条消息以表明该命令已发送。
但是,我无法将消息发送到频道。我尝试了这段代码:
import discord
import os
import random
import asyncio
testing_servers = [912361242985918464]
intents = discord.Intents().all()
bot = discord.Bot(intents=intents)
@bot.slash_command(guild_ids=testing_servers, name="announce", description="Make server announcements!")
async def announce(ctx, title, text, channel_id,anonymous=None):
#response embed
print(channel_id)
#announcement embed
embed_announce = discord.Embed(
colour = discord.Colour.blue(),
title=str(title),
description = text
)
await bot.get_channel(channel_id).send(embed = embed_announce)
但在尝试将其他消息发送回用户之前,我收到一条错误消息:AttributeError: 'NoneType' object has no attribute 'send'
.
我的结论是bot.get_channel(channel_id)
评估为None
。但为什么?我怎样才能得到正确的Channel
发送消息?
确保您发送一个整数到get_channel()
:
await bot.get_channel(int(channel_id)).send(embed=embed_announce)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)