当前位置: 首页>>代码示例>>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;未经允许,请勿转载。