Python Discord Bot在调用函数时将消息发布到特定通道

2024-05-19 03:21:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图定义一个函数,当调用该函数时,它会将消息发布到特定的discord通道。我不知道怎么做。这就是我目前所拥有的。有人能帮忙吗

编辑:我需要它在调用output()函数时运行,而不考虑其他事件

import discord
import asyncio

token = 'BOT TOKEN'
channelid = 'CHANNEL ID'

client = discord.Client()

def respond(output):
 #this should make a discord bot send a message with a value of output to the channel of channelid

client.run(token)
respond('hello world')


Tags: of函数importclienttokenasyncio消息编辑
1条回答
网友
1楼 · 发布于 2024-05-19 03:21:54

您可以使用bot.get_频道(channelid)

这只是一个示例,很抱歉,堆栈溢出中的格式设置不好

import discord

from discord.ext import commands

bot = commands.Bot(command_prefix='!')

@bot.event

async def on_ready():

    print(f'Logged in as {bot.user.name}')

    channel = bot.get_channel(yourchannelid) #a specific channel

    await channel.send('Bot is ready')

相关问题 更多 >

    热门问题