Skip to content

Instantly share code, notes, and snippets.

@krisppurg
Created May 30, 2021 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisppurg/4be3e2ebaab543dee02b711a3b0ca697 to your computer and use it in GitHub Desktop.
Save krisppurg/4be3e2ebaab543dee02b711a3b0ca697 to your computer and use it in GitHub Desktop.
Dimscord Nimconf 2021: My implementation of slash commands in dimscord
proc interactionCreate(s: Shard, i: Interaction) {.event(discord).} =
await discord.api.createInteractionResponse(i.id, i.token,
InteractionResponse(
kind: irtDeferredChannelMessageWithSource
)
)
let data = get i.data
case data.name:
of "beep", "beepo":
var content = data.options["message"].str.get
let invite = await discord.api.getInvite(
content,
# with_counts=with_counts,
auth=false
)
content = "```nim\n" & $invite & "\n```"
discard await discord.api.sendMessage(i.channel_id, content)
of "get-invite":
var with_counts = false
if "with_counts" in data.options:
with_counts = data.options["with_counts"].bval.get
var content = "???"
try:
let invite = await discord.api.getInvite(
data.options["code"].str.get,
with_counts=with_counts,
auth=false
)
content = "```nim\n" & $invite & "\n```"
except:
content = "An error occurred, perhaps invite was invalid."
await discord.api.editWebhookMessage(s.user.id, i.token,
"@original",
content=some content
)
else:
discard
## Also there is probably some junk code here, but as you can see the code was used for testing purposes,
## but hopefully that would give you an idea on what to implement on your bot.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment