简体   繁体   English

Discord.py | 发布消息

[英]Discord.py | Publish messages

does someone know how to publish a message by a user?有人知道如何发布用户消息吗? I have already tried a bit and asked on a discord coding server, but I didn't got a good answer.我已经尝试了一下,并在 discord 编码服务器上询问,但没有得到很好的答案。

I tried something like this:我试过这样的事情:

@client.event
async def on_message(message):
    if message.channel.type == discord.ChannelType.news:
        await message.publish
        return

I don't yet have the reputation to reply to Phoenix Doom directly.我还没有直接回复凤凰末日的声誉。 However I think bendix9009 is likely referring to the 'Publish ' option that you get when typing messages into 'Announcement' text channels.但是,我认为bendix9009 可能指的是您在“公告”文本通道中输入消息时获得的“发布”选项。

When you or a bot send a message into these channels, they are not published to any other channels that are following them by default.当您或机器人向这些频道发送消息时,默认情况下它们不会发布到跟随它们的任何其他频道。

It'd be useful to know whether you can just add some sort of flag onto the below line to publish those messages automatically.了解您是否可以在下面的行中添加某种标志以自动发布这些消息会很有用。

client.channels.cache.get(channelId).send; (Mine's written in javascript ) (我的写在javascript

Today I had the same problem and I fixed it with:今天我遇到了同样的问题,我用以下方法修复了它:

@client.command()
async def sendMessage(ctx, message):
    msg = await ctx.send("Published message: " + message)
    await msg.publish()

So I think you forgot the brackets.所以我想你忘记了括号。 So this code would work:所以这段代码可以工作:

@client.event
async def on_message(message):
    if message.channel.type == discord.ChannelType.news:
        await message.publish()
        return

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM