本文整理汇总了TypeScript中discord.js.Client.login方法的典型用法代码示例。如果您正苦于以下问题:TypeScript js.Client.login方法的具体用法?TypeScript js.Client.login怎么用?TypeScript js.Client.login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类discord.js.Client
的用法示例。
在下文中一共展示了js.Client.login方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例2: 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) => {
示例3: 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 => {
示例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();
}
示例5: joinChannel
})
/**
* Handle adding reactions
*/
client.on(`messageReactionAdd`, (reaction: MessageReaction, user: GuildMember) => {
if(reaction.message.channel.id === config.channelList) {
joinChannel(user, reaction.message.guild, reaction.message.content.split(` `, 1))
}
})
/**
* Handle removing reactions
*/
client.on(`messageReactionRemove`, (reaction: MessageReaction, user: GuildMember) => {
if(reaction.message.channel.id === config.channelList) {
leaveChannel(user, reaction.message.guild, reaction.message.content.split(` `, 1))
}
})
client.on(`raw`, rawEvent => rawReactionEmitter(rawEvent, client))
/**
* As soon as the bot is up and ready, confirm to console
* @listens ready
*/
client.on(`ready`, () => {
console.log(`Logged in as ${client.user.tag}!`)
})
/*
------------ EXECUTIONS ------------
*/
// Attempt to login by reading token from file
client.login(config.token)
示例6: ReactionCollector
disableEveryone: false,
disabledEvents: ['GUILD_MEMBER_ADD']
});
client.on('message', (message) => {
if (message.content === 'hello') {
message.channel.sendMessage('o/');
}
const collector: ReactionCollector = new ReactionCollector(message,
(reaction: MessageReaction) => reaction.emoji.toString() === '👌',
{ time: 30e3 });
collector.on('end', collected => console.log(collected));
});
client.login('dsfsd754.4fds4f68d4f6sd46f4s.7878easfdsgdfFDSIJIO');
export class TestCollector extends Collector<Snowflake, Message> {
public filter: CollectorFilter;
public constructor(client: Client, filter: CollectorFilter, ) {
super(client, filter);
}
public handle(message: Message): CollectorHandler<Snowflake, Message> {
return { key: message.id, value: message };
}
public cleanup(): void {}
public postCheck(): null { return null; }
}
示例7: resolve
return new Bluebird<void>((resolve, reject) => {
this.botClient.on("ready", () => {
resolve();
});
this.botClient.login(this.config.botToken).catch(reject);
}).timeout(READY_TIMEOUT).catch((err) => {