From Git directly:
$ v install --git https://github.com/DarpHome/discord.v
With VPM (soon, use Git):
$ v install DarpHome.discord
module main
import discord
import os
fn main() {
mut bot := discord.bot(os.getenv_opt('DISCORD_BOT_TOKEN') or {
eprintln('No token specified')
exit(1)
}, intents: .message_content | .guild_messages)
bot.events.on_ready.listen(fn (event discord.ReadyEvent) ! {
println('Logged as ${event.user.username}! Bot has ${event.guilds.len} guilds')
})
bot.events.on_message_create.listen(fn (event discord.MessageCreateEvent) ! {
if event.message.content != '!ping' {
return
}
event.creator.rest.create_message(event.message.channel_id, content: 'Pong')!
})
bot.launch()!
}
[!NOTE] Returning an error from event handler logs error, not panic the whole program. Don't forget enable
Message Contentintent in Developer Portal! Otherwise, your bot will shutdown with error:
...
2023-12-21 18:46:20.237000 [ERROR] Websocket closed with 4014 Disallowed intent(s).
2023-12-21 18:46:20.237000 [INFO ] Quit client listener, server(false)...
2023-12-21 18:46:20.238000 [ERROR] Recieved close code 4014: Disallowed intent(s): You sent a disallowed intent for a
Gateway Intent. You may have tried to specify an intent that you have not enabled or are not approved for.
V panic: result not set (Disallowed intent(s): You sent a disallowed intent for a Gateway Intent. You may have tried to
specify an intent that you have not enabled or are not approved for.)
...
multipart/form-data for file sendingapplication/json for sending without binary dataV
100.0%
From Git directly:
$ v install --git https://github.com/DarpHome/discord.v
With VPM (soon, use Git):
$ v install DarpHome.discord
module main
import discord
import os
fn main() {
mut bot := discord.bot(os.getenv_opt('DISCORD_BOT_TOKEN') or {
eprintln('No token specified')
exit(1)
}, intents: .message_content | .guild_messages)
bot.events.on_ready.listen(fn (event discord.ReadyEvent) ! {
println('Logged as ${event.user.username}! Bot has ${event.guilds.len} guilds')
})
bot.events.on_message_create.listen(fn (event discord.MessageCreateEvent) ! {
if event.message.content != '!ping' {
return
}
event.creator.rest.create_message(event.message.channel_id, content: 'Pong')!
})
bot.launch()!
}
[!NOTE] Returning an error from event handler logs error, not panic the whole program. Don't forget enable
Message Contentintent in Developer Portal! Otherwise, your bot will shutdown with error:
...
2023-12-21 18:46:20.237000 [ERROR] Websocket closed with 4014 Disallowed intent(s).
2023-12-21 18:46:20.237000 [INFO ] Quit client listener, server(false)...
2023-12-21 18:46:20.238000 [ERROR] Recieved close code 4014: Disallowed intent(s): You sent a disallowed intent for a
Gateway Intent. You may have tried to specify an intent that you have not enabled or are not approved for.
V panic: result not set (Disallowed intent(s): You sent a disallowed intent for a Gateway Intent. You may have tried to
specify an intent that you have not enabled or are not approved for.)
...
multipart/form-data for file sendingapplication/json for sending without binary dataV
100.0%