Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State.Application struct members are empty strings #1432

Open
Spacerulerwill opened this issue Aug 27, 2023 · 0 comments
Open

State.Application struct members are empty strings #1432

Spacerulerwill opened this issue Aug 27, 2023 · 0 comments

Comments

@Spacerulerwill
Copy link

Hello, new Go programmer here.

I am attempting to make a bot that will send an info message, setting the thumbnail to the icon of the bot. However, in my message call back when I try access the fields or members of the discordgo.State.Application struct I find that all of them apart from id and flags and set to either an empty string or null and I'm wondering why this is the case. My bot definitely has an icon, a name and these still give me empty strings. I have enabled all intents on discord developer portal and tried manually setting all intents in discordgo too with bot.Identify.Intents |= discordgo.AllIntents

Can anyone help? My code is below:

package bot

import (
	"fmt"
	"log"
	"os"
	"os/signal"
	"strings"

	"github.com/bwmarrin/discordgo"
)

const PREFIX string = "cs "

func Run(token string) {
	discord, err := discordgo.New("Bot " + token)

	if err != nil {
		log.Fatal(err)
	}

	discord.AddHandler(newMessage)

	discord.Open()
	defer discord.Close()

	fmt.Println("Bot is running...")

	// Run until code is terminated
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	<-c
}

func newMessage(bot *discordgo.Session, message *discordgo.MessageCreate) {
	if message.Author.Bot {
		return
	}

	messageContent := strings.ToLower(message.Content)

	if !strings.HasPrefix(messageContent, PREFIX) {
		return
	}

	command := strings.TrimSpace(strings.TrimPrefix(messageContent, PREFIX))

	switch command {
	case "info":
		embed := new(discordgo.MessageEmbed)
		embed.Description = bot.State.Application.Name // EMPTY!

		embed.Color = 0x313338
		thumbnail := new(discordgo.MessageEmbedThumbnail)
		thumbnail.URL = bot.State.Application.Icon // <- this is empty string!
		embed.Thumbnail = thumbnail
		bot.ChannelMessageSendEmbed(
			message.ChannelID,
			embed,
		)
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant