#Discordgo pass output of function as message

16 messages · Page 1 of 1 (latest)

pallid belfry
#

There no return type on func data()

glacial orbit
#

You need to put the return type in the function definition

#

like:

func data() *ExampleStruct {
       return &ExampleStruct
}
glacial orbit
#

Can i see the code, pls?

glacial orbit
#

You are supposed to return &data, and not &AutoGenerated in the function data()

#

And, you cannot use data() (value of type *AutoGenerated) as string value in argument to s.ChannelMessageSend, because it's not a string, if you want to, you'll need to format, probably using an fmt.Sprintf() function.

#

like:

fmt.Sprintf("Event %v\nNumber of Participants: %v\n", data.EventID, data.NumberOfParticipants)

glacial orbit
#

Can i see how you're using it (the Sprintf()), please?

uncut ridgeBOT
#

Types: 6
Functions: 23

Package fmt implements formatted I/O with functions analogous to C's printf and scanf. The format 'verbs' are derived from C's but are simpler....

More documentation omitted

glacial orbit
#

Yup, exactally

#

For print messages you can use fmt.Printf

uncut ridgeBOT
glacial orbit
#

When I suggested you use fmt.Sprintf(), it was to format the data, and then pass it formatted to s.ChannelMessageSend

#

Like, instead of use

s.ChannelMessageSend(m.ChannelID, data())

You should use:

str := fmt.Sprintf("Event %v\n", v.EventID)
s.ChannelMessageSend(m.ChannelID, str)

or just

s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("Event %v\n", v.EventID))
glacial orbit
#

Yep, you need to adjust it, I suppose the problem is in the structure, I suggest you evaluate what data is, and what the fields are in the structure

glacial orbit
#

In the str2 you are using fmt.Printf() instead of fmt.Sprintf(), and fmt.Printf() is used to print, not to assign or format values