#How do I connect my database to my Discord bot?

1 messages · Page 1 of 1 (latest)

tardy bramble
#

You'll need to inject your TicketMessage class into your command handler (assuming this is where your command implementation is), and call your database methods from within the command

tardy bramble
#

Add TicketMessage to your CommandHandler constructor. If you are using an IoC container, register the dependency.

tardy bramble
surreal beacon
#

ok so and another question, why is the

cmd.Parameters["@Id"].Value = TicketMessage.Id;
            cmd.Parameters["@Description"].Value = TicketMessage.Description;
            cmd.Parameters["@PingGuid"].Value = TicketMessage.PingGuid;
            cmd.Parameters["@Number"].Value = TicketMessage.Number;
            cmd.Parameters["@TicketGuid"].Value = TicketMessage.TicketGuid;```
#

gone red

tardy bramble
#

Looks like your datatype should be ticket not TicketMessage

surreal beacon
#

it says that TicketMessage does not contain a definition of Id and all of the others that are red.

tardy bramble
#

TicketMessage seems to be your class you use for interacting with the database. You have another file alongside it, ticket.cs, that I would guess has your object implementation

surreal beacon
#

I am trying to make a data module to store information for my ticket bot, I am recoding into cs

#

but cs is quite a bit different to js

tardy bramble
#

They are the properties you are trying to access, so your method should be

public void SaveTicketmessage(Ticket ticket)
{
  ...
  cmd.Parameters["@id"].Value = ticket.Id;
  ...
}
surreal beacon
#

ok

#

so once that is done, how do I add stuff to the database?

tardy bramble
#

That seems out of scope of this server, I'd suggest referencing docs for your database provider

surreal beacon
tardy bramble
#

fwiw it looks like your SaveTicketmessage should already be able to save to your database, I don't think you need any changes aside from using the Ticket object

surreal beacon
#

Oh.... cool 😄 thanks what about this, I can't seem to find anything on the discord.net website about how to make a link, I mean yes there is this link but it does not really tell about it.

https://discordnet.dev/guides/int_basics/message-components/buttons-in-depth.html#url

var button = new ComponentBuilder()
               .WithButton("Invite Me", url:"discordlink", ButtonStyle.Link );```
tardy bramble
#

[my text](https://discord.com/) should do it. If you want the url to be the text, [https://discord.com/](https://discord.com/)

surreal beacon
#

like this

tardy bramble
#

Not sure what you are trying to do specifically, looks like it works

surreal beacon
tardy bramble
surreal beacon
#

I have alrweady read that, and it does not show/tell how to use it with an url

tardy bramble
#

Try .WithButton("Invite Me", url: "https://...", style: ButtonStyle.Link);