【发布时间】:2021-06-22 22:30:33
【问题描述】:
我最近刚刚制作了一个这个机器人来在我的不和谐服务器上发送消息。该机器人工作正常,除了这个机器人将消息发送到我发送命令的同一文本通道。我想让这个机器人能够向特定的文本频道发送消息,同时我从私人文本频道发送命令。 这是代码:
import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio
from discord.ext.commands import has_permissions
client = commands.Bot(command_prefix="+")
@client.event
async def on_ready():
print('logged in as : ' + client.user.name)
print("the announce bot is ready")
@client.command()
@commands.has_permissions(kick_members=True)
async def ann(ctx,message):
channel = client.get_channel(ChannelID)
embed=discord.Embed(title=f"ANNOUNCEMENT GUYS !",description=message,color=0x9208ea)
embed.set_footer(text="Made by Fypo#0001")
await ctx.send(embed=embed)
client.run("token")
我已经输入了channel = client.get_channel(),但机器人继续将消息发送到我发送命令的同一个文本通道。有人可以帮忙吗?
【问题讨论】:
-
用你自己的话说,当你做
await ctx.send(embed=embed)时,你认为ctx部分是什么意思?你写了ctx.send,消息被发送到原文频道。你认为ann函数是如何知道存在这样一个频道的?您能想到ctx值可能与此相关的方式吗? -
"我已经把 channel = client.get_channel()如果您想发送到相应的频道,那么您应该以某种方式使用该对象......对吗?
-
我通过将
discord.py send message to channel放入搜索引擎找到了链接的副本。