question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I am getting error from the server for delete function

See original GitHub issue

I have just created a bot in telegraf for deleting the contact and give a temporary message. Unfortunately there is some error while running it.

bot.on('contact', preventContacts);

const preventContacts = async (ctx, next) => {
  const { from, contact } = ctx.message;
  // Delete contact
  await ctx.deleteMessage();
  // Give temporary message
  const { message_id } = await ctx.replyWithMarkdown(`Hi [${from.first_name||''} ${from.last_name||''}](tg://user?id=${from.id}) you put *${contact.first_name || ''} ${contact.last_name||''}*'s number which is not allowed in group please delete`);
  // Delete temporary message
  setTimeout(() => ctx.deleteMessage(message_id), 5 * 60 * 1000);
};

It seems to be the message deleted already and therefore getting error. Any one has clue how to fix it ?

  Error: 400: Bad Request: message can't be deleted
      at buildConfig.then.then.then.then (/Users/mymac/Work/bots/what-to-eat/node_modules/telegraf/core/network/client.js:254:17)
      at <anonymous>
      at process._tickDomainCallback (internal/process/next_tick.js:228:7)

Failed to process updates. { Error: 400: Bad Request: message can't be deleted
    at buildConfig.then.then.then.then (/Users/mymac/Work/bots/what-to-eat/node_modules/telegraf/core/network/client.js:254:17)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:228:7)
  code: 400,
  response:
   { ok: false,
     error_code: 400,                                                                                                          .json        yarn.lock
     description: 'Bad Request: message can\'t be deleted' },
  description: 'Bad Request: message can\'t be deleted',
  parameters: {},
  on:
   { method: 'deleteMessage',
     payload: { chat_id: 407853509, message_id: 567 } } }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
athimannilcommented, Sep 21, 2018

@Piterden Finally I have found a solution to know where the bot can delete or not in the group

const deleteJoinMessage = await ctx.deleteMessage().then((response) => response, ({ response }) => response.ok)

Please have a look and update you opinion

1reaction
Piterdencommented, Sep 4, 2018

I think next would work correct only inside .use() methods, which called middlewares. But I can make a mistake, and you better to check it out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP error in delete method not working properly
In my fake API, I have just 100 items and the last id is 100 when I put invalid id like 345 I...
Read more >
I get the error message "Could not delete from the specified ...
Open the delete query in Design view. · If the query property sheet is not open, press F4 to open it. · Click...
Read more >
4 Ways to Solve the Cannot Delete Files Error
Method 1: Force to Delete a File ... If even after several tries, you are repeatedly falling in deletion of a file or...
Read more >
Delete data from Cloud Firestore - Firebase
Delete documents. To delete a document, use the delete() method: ... If you need to delete entire collections, do so only from a...
Read more >
DELETE - HTTP - MDN Web Docs
The HTTP DELETE request method deletes the specified resource.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found