简体   繁体   中英

How to copy message from channel to channel in discord?

I'm trying to program a bot that can copy a message from one channel to another from any channel in discord, but the code that I typed in was not working even though I'm sure I followed the documentations correctly (hopefully).

@bot.command() #Moves a message from channel to channel
async def copymessage(ctx, message_id, channel_id):
    """
    Copy a message from channel to channel
    """
    guild = ctx.guild
    channel = guild.get_channel(int(channel_id))
    message = guild.fetch_message(int(message_id))
    print(f'Copying {message_id} to {channel_id}')
    await channel.send(message)

I have tried using a similar code (shown below) to test if I followed correctly. This code ran successfully and did what it was supposed to do.

channel = guild.get_channel(623681100778176513)
await channel.send("Sparkle is online!")

Maybe there's someone that can help me figure out the problem in my code?

fetch_message is an attribute of Messageable s (guilds are not messageable), so you need to use the channel.fetch_message . It also must be awaited.

message = await channel.fetch_message(int(message_id))

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