Reputation: 1106
I'm making a Discord bot to handle an announcement command. When the command is used, I want the bot to send a message in a specific channel and send a message back to the user to show that the command was sent.
However, I cannot get the message to be sent to the channel. I tried this code:
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)
But before even attempting to send the other message back to the user, I get an error that says AttributeError: 'NoneType' object has no attribute 'send'
.
I conclude that bot.get_channel(channel_id)
evaluated to None
. But why? How can I get the correct Channel
to send the message?
Upvotes: 4
Views: 1743
Reputation: 1439
Make sure you are sending an integer to get_channel()
:
await bot.get_channel(int(channel_id)).send(embed=embed_announce)
Upvotes: 3