Skip to content

Commit 9a4afb1

Browse files
feat: add reply
1 parent ab2624d commit 9a4afb1

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

index.js

+29-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ client.on('interactionCreate', async interaction => {
2222
if (commandName === 'se') {
2323
for (i = 0; i < 10; i++) {
2424
try {
25-
const res = await axios.get(process.env.URL, { timeout: 1000 });
25+
const res = await axios.get(process.env.API_URL + '/v2/random', { timeout: 1000 });
2626
const url = res.data;
2727
console.log('Get url: ' + url);
2828
await interaction.reply(url);
@@ -34,7 +34,7 @@ client.on('interactionCreate', async interaction => {
3434
} else if (commandName === 'mo') {
3535
for (i = 0; i < 10; i++) {
3636
try {
37-
const res = await axios.get(process.env.MOYU_URL, { timeout: 1000 });
37+
const res = await axios.get(process.env.API_URL + '/moyu', { timeout: 1000 });
3838
const text = res.data;
3939
await interaction.reply(text);
4040
return
@@ -60,5 +60,32 @@ client.on('interactionCreate', async interaction => {
6060
}
6161
});
6262

63+
64+
client.on('messageCreate', async message => {
65+
if (message.content === 'ping') {
66+
message.reply('Pong!');
67+
}
68+
const prefix = "/";
69+
if (
70+
!message.content.startsWith(prefix)
71+
|| message.author.bot
72+
|| message.content.length > 200
73+
) return;
74+
try {
75+
const res = await axios.post(
76+
process.env.API_URL + '/chatgpt',
77+
{
78+
token: process.env.API_TOKEN,
79+
text: message.content,
80+
chat_id: "discord"
81+
},
82+
{ timeout: 10000 }
83+
);
84+
const text = res.data;
85+
await message.reply(text);
86+
} catch (error) {
87+
console.error(error);
88+
}
89+
})
6390
// Login to Discord with your client's token
6491
client.login(process.env.DISCORD_TOKEN);

0 commit comments

Comments
 (0)