简体   繁体   中英

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.

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.

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 )

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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