bwmarrin / discordgo

(Golang) Go bindings for Discord
BSD 3-Clause "New" or "Revised" License
5.13k stars 819 forks source link

`ChannelMessageSend` returns HTTP 405 error #1461

Closed tenax66 closed 1 year ago

tenax66 commented 1 year ago

I got a 405 error HTTP 405 Method Not Allowed, {"message": "405: Method Not Allowed", "code": 0} for the following simple code that sends a message with a given channel ID. Did the Discord API actually not accept the method anymore?

package main

import (
    "log"

    "github.com/bwmarrin/discordgo"
)

func main() {
    token := "YOUR_BOT_TOKEN"

    dg, _ := discordgo.New("Bot " + token)

    _ = dg.Open()

    channelID := "TEXT_CHANNEL_ID"

    message := "Hello, world!"

    if _, err := dg.ChannelMessageSend(channelID, message); err != nil {
        log.Println("Error sending message:", err)
        return
    }

    dg.Close()
}
tenax66 commented 1 year ago

Sorry for the trouble, I resolved this. The channelID I gave was incorrect so that error occured. (though different from the error message)