當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript discord.js.Client類代碼示例

本文整理匯總了TypeScript中discord.js.Client的典型用法代碼示例。如果您正苦於以下問題:TypeScript js.Client類的具體用法?TypeScript js.Client怎麽用?TypeScript js.Client使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了js.Client類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getClient

 public async getClient(userId: string | null = null): Promise<DiscordClient> {
     if (userId === null) {
         return this.botClient;
     }
     if (this.clients.has(userId)) {
         log.verbose("Returning cached user client for", userId);
         return this.clients.get(userId) as DiscordClient;
     }
     const discordIds = await this.store.get_user_discord_ids(userId);
     if (discordIds.length === 0) {
         return Promise.resolve(this.botClient);
     }
     // TODO: Select a profile based on preference, not the first one.
     const token = await this.store.get_token(discordIds[0]);
     const client = new DiscordClient({
         fetchAllMembers: true,
         messageCacheLifetime: 5,
         sync: true,
     });
     const jsLog = new Log("discord.js-ppt");
     client.on("debug", (msg) => { jsLog.verbose(msg); });
     client.on("error", (msg) => { jsLog.error(msg); });
     client.on("warn", (msg) => { jsLog.warn(msg); });
     try {
         await client.login(token);
         log.verbose("Logged in. Storing ", userId);
         this.clients.set(userId, client);
         return client;
     } catch (err) {
         log.warn(`Could not log ${userId} in. Returning bot user for now.`, err);
         return this.botClient;
     }
 }
開發者ID:Half-Shot,項目名稱:matrix-appservice-discord,代碼行數:33,代碼來源:clientfactory.ts

示例2: createConnection

createConnection(connectionOptions).then(conn => {
    try {
    console.log("Typeorm connected to database.");

    var bot = new Discord.Client();

    bot.on('ready', () => readyEvent(bot));
    bot.on('presenceUpdate', presenceEvent);
    bot.on('message', messageEvent(bot));

    bot.login(Configuration.DISCORD_TOKEN);
    } catch (ex) {
        console.error(ex);
    }
}).catch(err => {
開發者ID:Goyatuzo,項目名稱:LurkerBot,代碼行數:15,代碼來源:app.ts

示例3: makeDiscordDriver

export function makeDiscordDriver (token: string): Function {
  let client = new Client()
      client.loginWithToken(token)

  function discordDriver (request: Observable<any>, runSA: StreamAdapter): DiscordSource {
    let response = request.share()
        response.subscribe(x => console.log('fugg reply'), err => console.log(err))

    let discordSource = new MainDiscordSource(client, response, runSA)

    return discordSource
  }

  (discordDriver as any).streamAdapter = rxjsAdapter

  return discordDriver
}
開發者ID:goodmind,項目名稱:cycle-discord,代碼行數:17,代碼來源:discord-driver.ts

示例4: constructor

    constructor(config){
        this.token = config.token;
        this.prefix = config.prefix;
        this.presence = config.presence;

        this.database = new DB();

        this.client = new Client(); // init the discord client
        this.client.login(this.token); // login to the discord API
        
        this.commandHandler = new CommandHandler();

        this.guilds = [];
        
        this.loadCommands();
    }
開發者ID:Avuxo,項目名稱:senjou,代碼行數:16,代碼來源:senjou.ts

示例5: getDiscordId

 public async getDiscordId(token: string): Promise<string> {
     const client = new DiscordClient({
         fetchAllMembers: false,
         messageCacheLifetime: 5,
         sync: false,
     });
     return new Bluebird<string>((resolve, reject) => {
         client.on("ready", async () => {
             const id = client.user.id;
             await client.destroy();
             resolve(id);
         });
         client.login(token).catch(reject);
     }).timeout(READY_TIMEOUT).catch((err: Error) => {
         log.warn("Could not login as a normal user.", err.message);
         throw Error("Could not retrieve ID");
     });
 }
開發者ID:Half-Shot,項目名稱:matrix-appservice-discord,代碼行數:18,代碼來源:clientfactory.ts

示例6: rawReactionEmitter

export async function rawReactionEmitter(rawEvent: any, client: Client) {
  if(!reactionEvents.hasOwnProperty(rawEvent.t)) {
    return
  }

  const
    { d: data } = rawEvent,
    user: User = client.users.get(data.user_id),
    channel: TextChannel = client.channels.get(data.channel_id) as TextChannel

  if(channel.messages.has(data.message_id)) {
    return
  }

  const
    message: Message = await channel.fetchMessage(data.message_id),
    emojiKey: string = (data.emoji.id) ? `${data.emoji.name}:${data.emoji.id}` : data.emoji.name,
    reaction = message.reactions.get(emojiKey)
  
  client.emit(reactionEvents[rawEvent.t], reaction, user)
}
開發者ID:Zunon,項目名稱:Sagiri,代碼行數:21,代碼來源:handlers.ts

示例7: async

 return new Bluebird<string>((resolve, reject) => {
     client.on("ready", async () => {
         const id = client.user.id;
         await client.destroy();
         resolve(id);
     });
     client.login(token).catch(reject);
 }).timeout(READY_TIMEOUT).catch((err: Error) => {
開發者ID:Half-Shot,項目名稱:matrix-appservice-discord,代碼行數:8,代碼來源:clientfactory.ts

示例8: start

    public start(): void{
        // start the bot
        this.client.on("ready", () => {
            // initialize the guild objects for the bot instance
            this.initGuilds();


            
            // set the 'playing' status
            this.client.user.setPresence({game: {name: this.presence, type: 0}});

            
            // print startup time
            console.log("Bot started @ " + this.getTime());
        
        });

        // message in view
        this.client.on("message", (msg) => {
            // get description
            if(msg.content.startsWith(this.prefix + "desc")){
                let command = msg.content.substr(1).split(" ").slice(1);
                let response = this.commandHandler.getDescription(command);
                if(response != undefined) { msg.channel.send(response); }
            // get command
            } else if(msg.content.startsWith(this.prefix)){
                let command = msg.content.substr(1).split(" ");
                let args = command.slice(1);
                args.db = this.database;
                
                // find the guild object where the ID matches.
                let guild = this.guilds.find(g => g.id == msg.guild.id);
                if(guild != undefined && guild.checkCooldown(command, 1000)){
                    let response = this.commandHandler.execCommand(command[0], args);
                    // make sure response is valid.
                    if(response != undefined) { msg.channel.send(response); }
                }
            }
        });

        // join new guild
        this.client.on("guildCreate", (guild) => {
            this.database.addGuild(guild);
        });

        // removed from guild
        this.client.on("guildDelete", (guild) => {
            this.database.deleteGuild(guild);
        });

        
    }
開發者ID:Avuxo,項目名稱:senjou,代碼行數:52,代碼來源:senjou.ts

示例9:

client.on('ready', () => {

    client.userAgent.url     = module.exports.homepage;
    client.userAgent.version = module.exports.version;
    client.setPlayingGame(config.get('settings.discordStatus') + '');

    console.dir(client.servers.map(s => s.name));
    const logServer = client.servers.get(config.get('settings.logServer'));
    if (logServer) init(logServer);
    else console.error('Not admitted to log server');
});
開發者ID:fernozzle,項目名稱:poppin-bot,代碼行數:11,代碼來源:server.ts

示例10: reevaluateVoiceChannel

    /**
     * Finds the most populous voice channel and joins it
     */
    function reevaluateVoiceChannel(server:Discord.Server):Promise<any> {
        if (server.channels.length === 0) return Promise.resolve();

        let [biggest, bigCount]:[Discord.VoiceChannel, number] = [null, -1];
        for (const test of server.channels.getAll('type', 'voice')) {
            const testCount = test.members.length -
                (test.members.get(client.user.id) ? 1 : 0);
            if (testCount < bigCount || testCount < 1) continue;
            [biggest, bigCount] = [test, testCount];
        }
        // Join biggest, maybe leaving another
        if (biggest) return biggest.join();

        // Just leave
        const conn = client.voiceConnections.get('server', server);
        if (conn) return client.leaveVoiceChannel(conn.voiceChannel);
        return Promise.resolve();
    }
開發者ID:fernozzle,項目名稱:poppin-bot,代碼行數:21,代碼來源:server.ts


注:本文中的discord.js.Client類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。