【问题标题】:How do i make this discord bot to send message to specific channel? [duplicate]我如何让这个不和谐机器人向特定频道发送消息? [复制]
【发布时间】: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 放入搜索引擎找到了链接的副本。

标签: python discord bots


【解决方案1】:

那是因为你向 ctx 发送消息。您应该将它发送到您使用 get_channel() 获得的通道对象。

await channel.send(embed=embed)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-14
    • 1970-01-01
    • 2021-06-17
    • 2020-12-18
    • 2019-07-11
    • 2020-07-23
    • 2020-07-14
    • 2020-12-26
    相关资源
    最近更新 更多