因此,我在discord.py中创建了一个bot命令,用户输入该命令,然后给它一些输入,然后代码将输入放到一个嵌入式中并发送它.我希望有一种方法能够将结果发送到发送命令的同一通道. 我读过有关发送消息的文章,但很多人说需要有通道ID才能发送消息,但我希望它将消息发送到运行该命令的同一通道. 你能帮我解决这个问题吗?

EDIT个 代码如下:

@bot.command(name="fban")
async def fban(ctx):
    # This will make sure that the response will 
    # only be registered if the following
    # conditions are met:
    def check(msg):
        return msg.author == ctx.author and msg.channel == ctx.channel
    msg = await bot.wait_for("message", check=check)
    outmsg = msg.content.lower()
    username = outmsg.splitlines()[0]
    reason = outmsg.splitlines()[1]

    fake_ban_embed = discord.Embed(title="{username} was 
    banned.",description="Reason : {reason}")
    fake_ban_embed.set_thumbnail(url='https://imgur.com/FkqtqE8')

    await message.reply(embed=fake_ban_embed)
    

推荐答案

该命令将自动发送到用户调用它时的同一通道(除非您指定了发送消息的通道)

@bot.command()
async def mycommand(ctx: commands.Context, arg1: str, ...):
  await ctx.send("...")  # the msg "..." will be sent to the same channel

  embed = discord.Embed(title="...", description="...")  # create an embed
  await ctx.send(embed=embed)  # embed will be sent to the same channel

  await ctx.reply("...")  # reply to the same channel

  # specify a channel to send sth
  channel = bot.get_channel(CHANNEL_ID)  # this will work if you cache channels  during startup
  # otherwise use "channel = await bot.fetch_channel(CHANNEL_ID)" but this is an API call
  await channel.send("...", embed=embed)  # this will send to the channel you specified

Python相关问答推荐

强制venv在bin而不是收件箱文件夹中创建虚拟环境

由于瓶颈,Python代码执行太慢-寻求性能优化

Python中的负前瞻性regex遇到麻烦

剧作家Python没有得到回应

多处理代码在while循环中不工作

如何根据日期和时间将状态更新为已过期或活动?

Python daskValue错误:无法识别的区块管理器dask -必须是以下之一:[]

如何将ctyles.POINTER(ctyles.c_float)转换为int?

如何制作10,000年及以后的日期时间对象?

大小为M的第N位_计数(或人口计数)的公式

基于索引值的Pandas DataFrame条件填充

使用密钥字典重新配置嵌套字典密钥名

通过ManyToMany字段与Through在Django Admin中过滤

lityter不让我输入左边的方括号,'

导入错误:无法导入名称';操作';

干燥化与列姆化的比较

Odoo16:模板中使用的docs变量在哪里定义?

使用__json__的 pyramid 在客户端返回意外格式

处理Gekko的非最优解

jsonschema日期格式