add method for check discord join and role
This commit is contained in:
parent
951122c1a7
commit
49c02ca3d3
@ -7,8 +7,8 @@ const DISCORD_API_HOST = 'https://discord.com/api/v10'
|
|||||||
* DISCROD_GUILD_ID
|
* DISCROD_GUILD_ID
|
||||||
* DISCORD_BOT_TOKEN
|
* DISCORD_BOT_TOKEN
|
||||||
*/
|
*/
|
||||||
export async function getGuildMember(uid: string) {
|
export async function getGuildMember(guid: string, uid: string) {
|
||||||
const url = `${DISCORD_API_HOST}/guilds/${process.env.DISCROD_GUILD_ID}/members/${uid}`
|
const url = `${DISCORD_API_HOST}/guilds/${guid}/members/${uid}`
|
||||||
const token = process.env.DISCORD_BOT_TOKEN
|
const token = process.env.DISCORD_BOT_TOKEN
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
headers: {
|
headers: {
|
||||||
@ -24,9 +24,9 @@ export async function getGuildMember(uid: string) {
|
|||||||
* @param uid
|
* @param uid
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export async function checkJoinGuld(uid: string) {
|
export async function checkJoinGuld(guid: string, uid: string) {
|
||||||
try {
|
try {
|
||||||
const res = await getGuildMember(uid)
|
const res = await getGuildMember(guid, uid)
|
||||||
/**
|
/**
|
||||||
* if user not in guild, res will be:
|
* if user not in guild, res will be:
|
||||||
* {
|
* {
|
||||||
@ -48,9 +48,9 @@ export async function checkJoinGuld(uid: string) {
|
|||||||
* @param roleId
|
* @param roleId
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export async function checkGotRole(uid: string, roleId: string) {
|
export async function checkGotRole(guid: string, uid: string, roleId: string) {
|
||||||
try {
|
try {
|
||||||
const res = await getGuildMember(uid)
|
const res = await getGuildMember(guid, uid)
|
||||||
if (res.code === 10013) {
|
if (res.code === 10013) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user