如何在不和谐上使用表情符号反应获得相互作用的URL请求?
我不使用discord.js,因为我的代码在AWS lambda上运行。
因此,我在Discord Developer站点上注册了交互端点url
。
并在 oauth2 url Generator
上选择的选择范围。
邀请bot已成功。然后我输入一些消息,然后添加emoji
但是当我在AWS上检查AWS时CloudWatch,它没有记录。
验证代码已编写。斜杠命令效果很好。但是机器人不读取消息和表情符号。
Bot如何使用Discord 交互端点URL
获得消息或表情符号?
// interactionRouter.ts
/* eslint-disable @typescript-eslint/no-misused-promises */
import express from 'express';
import {
interactDiscordController,
interactUserController,
} from '../controller/interactController';
export const interactionRouter = express.Router();
interactionRouter.post('/', interactDiscordController());
interactionRouter.get('/test', (_req, res) => {
return res.status(200).json({
message: 'Hello from router!',
});
});
interactionRouter.use(express.json());
interactionRouter.post('/user-info', interactUserController());
// interactionController.ts
import { Request, Response } from 'express';
import DirectMessageToUserUseCaseDto from '../../../core/dto/directMessageToUserUseCaseDto';
import SetUserRoleOnDiscordDto from '../../../core/dto/setUserRoleOnDiscordDto';
import DirectMessageToUserUseCase from '../../../core/usecase/directMessageToUserUseCase';
import SetUserRoleOnDiscordUseCase from '../../../core/usecase/setUserRoleOnDiscordUseCase';
// TODO usecase inject
export const interactDiscordController =
() => async (req: Request, res: Response) => {
try {
console.log(`req : `);
console.log(req);
const usecase = new DirectMessageToUserUseCase();
const dto = new DirectMessageToUserUseCaseDto();
const isDtoCreated = await dto.create(req);
if (!isDtoCreated) {
return res.status(400).send(false);
}
const result:
| {
status: number;
message: string;
}
| { status: number; message: { type: number } } = usecase.execute(dto);
return res.status(result.status).send(result.message);
} catch (error) {
console.error(error);
return false;
}
};
//directMessageToUserUseCase.ts
/* eslint-disable @typescript-eslint/restrict-plus-operands */
import DirectMessageToUserUseCaseDto from '../dto/directMessageToUserUseCaseDto';
import nacl from 'tweetnacl';
import dotenv from 'dotenv';
import { resolve } from 'path';
dotenv.config({
path: resolve(__dirname, `../../.env.${String(process.env.NODE_ENV)}`),
});
export default class DirectMessageToUserUseCase {
verify(dto: DirectMessageToUserUseCaseDto) {
try {
console.log(
`DISCORD_PUBLIC_KEY ${String(process.env.DISCORD_PUBLIC_KEY)}`
);
console.log(`signature ${String(dto.signature)}`);
console.log(`timestamp ${String(dto.timestamp)}`);
const isVerified = nacl.sign.detached.verify(
Buffer.from(dto.timestamp + dto.rawBody),
Buffer.from(dto.signature, 'hex'),
Buffer.from(String(process.env.DISCORD_PUBLIC_KEY), 'hex')
);
console.log(`isVerified ${String(isVerified)}`);
if (!isVerified) {
console.log('Failed verification');
return {
status: 401,
message: 'invalid request signature',
};
}
console.log('Handling validation test request');
return {
status: 200,
message: { type: 1 },
};
} catch (error) {
console.error(error);
return {
status: 400,
message: 'Error handling verification',
};
}
}
execute(dto: DirectMessageToUserUseCaseDto) {
if (dto.body === undefined) {
return {
status: 400,
message: 'DM failed',
};
}
console.log(`body ${JSON.stringify(dto.body)}`);
if (
(process.env.NODE_ENV === 'dev' ||
process.env.NODE_ENV === 'production') &&
Number(dto.body.type) === 1
) {
return this.verify(dto);
}
try {
/*
TODO
vercel 프론트엔드 주소와 유저 id를 알려주고 주소 클릭해서 지갑 연결, id 입력하라고 DM 보낸다.
*/
const url = 'https://www.google.com/';
const userId: string = dto.body.user.id;
return {
status: 200,
message: {
type: 4,
data: {
content: `click this [link](${url}) to connect wallet and then type your user id -> ${String(
userId
)}`,
},
},
};
} catch (error) {
console.error(error);
return {
status: 400,
message: 'DM failed',
};
}
}
}
当我在“机器人”存在的频道上发送消息或表情符号时,我无法获得 console.log(req)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我得出的结论是,相互作用URL中没有表情符号听力功能。
因此,我创建了 button ,最后获得信号。
I concluded there is no emoji listening function in interaction url.
So I created button and finally get signal that button clicked.
似乎您没有指定配置客户端时指定“ MessageContent”和“ guildmessagereactions”意图。
在discord.js v14中可以这样工作:
以下是所有网关意图的列表: https://discord.com/developers/docs/topics/gateway#list-of--of-intents
It seems like you have not specified the 'MessageContent' and 'GuildMessageReactions' intents when configuring your client.
In discord.js v14 that would work like this:
Here is a list of all the gateway intents: https://discord.com/developers/docs/topics/gateway#list-of-intents