将bot.event()打印到特定的discord通道



我想让我的机器人发送它"我连接到不和";消息发送到特定的不和频道。这是我的代码目前

import random
import discord
import time 
from discord.ext import commands, tasks
bot = commands.Bot(command_prefix='!')
TOKEN = ''
@bot.event
async def on_ready(ctx):
channel = bot.get_channel(774970601013379092)
await channel.send(f'{bot.user.name} has connected to Discord!')
@bot.command()
async def hello(ctx):
await ctx.send(f"Hello World")
@bot.command()
@commands.is_owner()
async def shutdown(ctx):
await ctx.send(f"{bot.user.name} is shutting down. . .")
await ctx.bot.logout()
print(f'{bot.user.name} has disconnected from Discord!')

# c_sharp_challenges channel
@bot.command()
async def csharp(ctx):
channel = bot.get_channel(774683687018037249)
await channel.send('Welcome To C#!')
# html_challenges channel
@bot.command()
async def html(ctx):
channel = bot.get_channel(774683714399371316) 
await channel.send('Welcome To HTML!')
# java_challenges channel
@bot.command()
async def java(ctx):
channel = bot.get_channel(774683618307342417)
await channel.send('Welcome To Java!')
# java_script_challenges channel
@bot.command()
async def javascript(ctx):
channel = bot.get_channel(774683653728501761) 
await channel.send('Welcome to Java Script!')
# python_challenges channel
@bot.command()
async def python(ctx):
channel = bot.get_channel(774683556077109258)
await channel.send('Welcome To Python!')

bot.run(TOKEN)

我似乎在stackoverflow或谷歌上找不到任何能帮助我解决这个问题的东西。它在python中,如果这很重要的话,我在ubuntu 20.04上

机器人向某个频道发送一条消息,表明它处于联机状态。如果要更改频道,只需更改on_ready函数中给定的channel_id即可。

我碰巧注意到我有00000个通道ID

@bot.event
async def on_ready():
print("bot is ready")
channel = bot.get_channel(774970601013379092)
await channel.send("bot is online")