本文整理匯總了TypeScript中discord.js.RichEmbed.setDescription方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript js.RichEmbed.setDescription方法的具體用法?TypeScript js.RichEmbed.setDescription怎麽用?TypeScript js.RichEmbed.setDescription使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類discord.js.RichEmbed
的用法示例。
在下文中一共展示了js.RichEmbed.setDescription方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
const buildMessage = (eqs: IEQ[], ships: number[]) => {
let shipnumbers = [":one:", ":two:", ":three:", ":four:", ":five:", ":six:", ":seven:", ":eight:", ":nine:", ":keycap_ten:"];
const embed = new Discord.RichEmbed();
embed.setAuthor("PSO2 Emergency Quest Alert", "https://images.emojiterra.com/mozilla/512px/231a.png");
embed.setColor("GREEN");
embed.setDescription('<:H_Line_Bold:386614101503246348>Ships<:H_Line_Bold:386614101503246348>');
eqs
.filter(eq => ships.includes(eq.ship))
.forEach(eq => {
embed.description += `\n ⢠${shipnumbers[eq.ship - 1]}<:V_Line:386619978994024458>${eq.name}`;
});
if (eqs.length > 9) {
embed.setDescription('<:H_Line_Bold:386614101503246348>All Ships<:H_Line_Bold:386614101503246348>');
embed.description += `\n ⢠${eqs[0].name}`;
}
embed.description += "\n\n[Help?](https://bit.ly/2KRb1De)";
return embed;
}
示例2: GetEmbedForReply
public async GetEmbedForReply(
event: IMatrixEvent,
channel: Discord.TextChannel,
): Promise<Discord.RichEmbed|undefined> {
if (!event.content) {
event.content = {};
}
const relatesTo = event.content["m.relates_to"];
let eventId = "";
if (relatesTo && relatesTo["m.in_reply_to"]) {
eventId = relatesTo["m.in_reply_to"].event_id;
} else {
return;
}
const intent = this.bridge.getIntent();
// Try to get the event.
try {
const sourceEvent = await intent.getEvent(event.room_id, eventId);
sourceEvent.content.body = sourceEvent.content.body || "Reply with unknown content";
const replyEmbed = (await this.EventToEmbed(sourceEvent, channel, false)).messageEmbed;
// if we reply to a discord member, ping them!
if (this.bridge.getBot().isRemoteUser(sourceEvent.sender)) {
const uid = new MatrixUser(sourceEvent.sender.replace("@", "")).localpart.substring("_discord".length);
replyEmbed.addField("ping", `<@${uid}>`);
}
replyEmbed.setTimestamp(new Date(sourceEvent.origin_server_ts));
if (this.HasAttachment(sourceEvent)) {
const mxClient = this.bridge.getClientFactory().getClientAs();
const url = mxClient.mxcUrlToHttp(sourceEvent.content.url);
if (["m.image", "m.sticker"].includes(sourceEvent.content.msgtype as string)
|| sourceEvent.type === "m.sticker") {
// we have an image reply
replyEmbed.setImage(url);
} else {
const name = this.GetFilenameForMediaEvent(sourceEvent.content);
replyEmbed.description = `[${name}](${url})`;
}
}
return replyEmbed;
} catch (ex) {
log.warn("Failed to handle reply, showing a unknown embed:", ex);
}
// For some reason we failed to get the event, so using fallback.
const embed = new Discord.RichEmbed();
embed.setDescription("Reply with unknown content");
embed.setAuthor("Unknown");
return embed;
}
示例3: EventToEmbed
public async EventToEmbed(
event: IMatrixEvent, channel: Discord.TextChannel, getReply: boolean = true,
): Promise<IMatrixEventProcessorResult> {
const mxClient = this.bridge.getClientFactory().getClientAs();
let profile: IMatrixEvent | null = null;
try {
profile = await mxClient.getStateEvent(event.room_id, "m.room.member", event.sender);
if (!profile) {
profile = await mxClient.getProfileInfo(event.sender);
}
if (!profile) {
log.warn(`User ${event.sender} has no member state and no profile. That's odd.`);
}
} catch (err) {
log.warn(`Trying to fetch member state or profile for ${event.sender} failed`, err);
}
const params = {
mxClient,
roomId: event.room_id,
userId: event.sender,
} as IMatrixMessageProcessorParams;
if (profile) {
params.displayname = profile.displayname;
}
let body: string = "";
if (event.type !== "m.sticker") {
body = await this.matrixMsgProcessor.FormatMessage(event.content as IMatrixMessage, channel.guild, params);
}
const messageEmbed = new Discord.RichEmbed();
messageEmbed.setDescription(body);
await this.SetEmbedAuthor(messageEmbed, event.sender, profile);
const replyEmbed = getReply ? (await this.GetEmbedForReply(event, channel)) : undefined;
if (replyEmbed && replyEmbed.fields) {
for (let i = 0; i < replyEmbed.fields.length; i++) {
const f = replyEmbed.fields[i];
if (f.name === "ping") {
messageEmbed.description += `\n(${f.value})`;
replyEmbed.fields.splice(i, 1);
break;
}
}
}
return {
messageEmbed,
replyEmbed,
};
}