translate

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

README

Discord Translate bot

Build Status Godoc

A Translate bot using discordgo and Google Translate API.

To translate a message into a given language, react to it with the desired language flag. The source language is automatically detected.

Example

import (
  translate "github.com/StalkR/discordgo-translate"
)

b := translate.New("<bot token>", "<Google Translate API token>")
if err := b.Start(); err != nil {
  log.Fatal(err)
}
defer b.Close()

log.Printf("Discord Translate bot running - press CTRL-C to exit")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc

Acknowledgements

Discord Go bindings: bwmarrin/discordgo (doc).

Inspiration: Smoogle Translate, unfortunately the developers intentionally refuse to translate messages from other bots, so I had to make my own.

Bugs, comments, questions

Create a new issue.

Documentation

Overview

Package translate is a Discord bot library to translate messages with Google Translate API.

import translate "github.com/StalkR/discordgo-translate"

Discord bot setup:

Add a Google Translate API key and start the bot.

To translate a message into a given language, react to it with the desired language flag. The source language is automatically detected.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot struct {
	// contains filtered or unexported fields
}

A Bot represents a Discord Translate bot.

Example
b := New("<Discord bot token>", "<Google Translate API token>")
if err := b.Start(); err != nil {
	log.Fatal(err)
}
defer b.Close()

log.Printf("Discord Translate bot running - press CTRL-C to exit")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
Output:

func New

func New(token string, apiKey string) *Bot

New creates a new Discord Translate bot. Requires a Discord bot token and a Google Translate API key.

func (*Bot) Close

func (b *Bot) Close() error

Close closes the bot: handler uninstalled and Discord session closed. Bot can be started again.

func (*Bot) Start

func (b *Bot) Start() error

Start starts the bot, connecting it to Discord.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL