#Discordgo pass output of function as message
16 messages · Page 1 of 1 (latest)
You need to put the return type in the function definition
like:
func data() *ExampleStruct {
return &ExampleStruct
}
Can i see the code, pls?
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)
Can i see how you're using it (the Sprintf()), please?
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
func (s *Session) ChannelMessageSend(channelID string, content string, options ...RequestOption) (*Message, error)
```
ChannelMessageSend sends a message to the given channel. channelID : The ID of a Channel. content : The message to send.
An MessageEmbed stores data for message embeds.
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))
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
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