discord.gateway: Shard ID None has successfully RESUMED session - discord.py

While executing the function in the while loop, no error occurred, but "discord.gateway: Shard ID None has successfully RESUMED session " is displayed, and the loop execution stops. Does anyone know a solution?
while True:
response = requests.get(account_creation_date_url)
html = response.text
soup = BeautifulSoup(html, 'html.parser')
titles = soup.select_one('#serverPage > div > div > div > div > div > div > span')
#print(titles.get_text())
await asyncio.sleep(3.0)

Related

button press command works, but still says interaction failed; using discord-components

The code does what is supposed to do, but after each button press it says "This interaction failed". Pressing the button edits the embed to change it to another. How would I get rid of that interaction failed message after pressing a button?
the issue: https://i.stack.imgur.com/i4dTd.png
code received from: https://github.com/elixss/YouTube/blob/main/source/buttons.py
Here is the code:
#bot.group(invoke_without_command=True)
async def help(ctx):
# buttons
one = Button(style=1, label="Commands", id="em1")
two = Button(style=1, label="Depression", id="em2")
three = Button(style=1, label="Moderator", id="em3")
four = Button(style=1, label="Language", id="em4")
# embeds
em1 = Embed(title="Commands Plugin",color=0x5865F2)
em2 = Embed(title="Depression Plugin", description="placeholder", color=0x5865F2)
em3 = Embed(title="Moderator Plugin", description="placeholder", color=0x5865F2)
em4 = Embed(title="Language Plugin", description="placeholder", color=0x5865F2)
# main help embed
help_embed = Embed(description="> **Help Module**\nPress on any button to view the commands for that selected plugin.",
color=discord.Color.random())
# buttons to embeds
buttons = {
"em1": em1,
"em2": em2,
"em3": em3,
"em4": em4
}
msg = await ctx.send(embed=help_embed,
components=[[one, two, three, four]])
while True:
event = await bot.wait_for("button_click", timeout=60.0)
if event.channel is not ctx.channel:
return
if event.channel == ctx.channel:
response = buttons.get(event.component.id)
await msg.edit(embed=response)
if response is None:
await event.channel.send("error, try again.")
As Elias said, you have to response to interactions, else it will show "This interaction failed", but not with a regular ctx.send() but with (in your case)
await event.respond(type=4, message="Responded!")
If you don't want to send a message as a response to a button click or selection in a select, you can just use type=6 without message:
await event.respond(type=6)
For more types, see the documentation.
The best way to do this is to either remove all buttons after it's been pressed, or add a cooldown that will remove the buttons automatically after a certain time.
In your situation, it would look something like this:
msg = await ctx.send(embed=help_embed, components=[[one, two, three, four]])
try:
res = await client.wait_for("button_click", timeout = 60)
except asyncio.TimeoutError:
await msg.edit(components = []) #removes buttons from message
else:
if res.author == message.author:
#when button is clicked
await msg.edit(components = [])
This also prevents being rate limited, so you don't have buttons constantly waiting for a response.

Telerik RadTreeViews Ajax Timeout - How to test for timeout

I have an Ajaxed RadTreeiew. When its nodes are clicked the information area is populated from the database. However, if ajax has timed out, clicking the nodes will just show nothing in the information area.
I've tried increasing the AsyncPostBackTimeout in the script manager but with no luck. Also tried telerik support.
What i need is to be able to test for the ajax timeout on each node click and if timed out then redirect back to the same page, to refresh it.
Treenode click event below...
Public Sub RTV1_ItemClick(ByVal sender As Object, ByVal e As RadTreeNodeEventArgs) Handles RTV1.NodeClick
'session timeoutcheck
If Session(courseID & "-MyTreeView") = Nothing Then
Session(courseID & "-SiteconID") = 0
Response.Redirect(Request.Url.ToString)
End If
'This is a tree node click so set the TabID session to 0
Session(courseID & "-TabID") = 0
'expand child nodes here
e.Node.ExpandParentNodes()
e.Node.Expanded = True
e.Node.Selected = True
'setup the content
SetUpContent(e.Node.Value, courseID)
End Sub

How to dynamically load carousel items in Sencha

I have a problem with my product view. I want to display product data. each product is a "box" with an image and text. I want to display six products on a panel. As of the fact that i have many products i want to have a "carousel like view". My idea was the following: Place 6 products on a panel. Load 3 panels and place each panel as a carousel item so that i can swipe to get to another "page".
To save performance I tried to always have only 3 items in the carousel. The active "page" and the page before, and the page after, so that I can swipe to left/right and the next page can be loaded.
I tried to put my logic in the "onActiveItemChange"-Listener of the carousel, but I had massive problems with adding/removing carousel items. So my Question is is it possible to do what i want to accomplish?
Is there a better alternative? Of course my data is in a store, but I don't want that standard list view.
Another Question: Because my first attempt with the carousel failed i tried to build a Ext.Container (card layout) with the panels on it. But how can I listen to a swipe event on a Panel???
thanks for help ;-)
Even I am doing the same, using carousel & a store. Every page of carousel is a view(panel) which would have 4/6 child views(panels). On store load I am creating those children and then divide them into pages and add those pages to carousel.
This is working fine for me and on activeItemChange I am loading more pages:
activeitemchange: function(container, value, oldValue, eOpts) {
var activeItemIndex = container.getActiveIndex();
var galleryTotal = container.getInnerItems() ? container.getInnerItems().length : 0;
if ((activeItemIndex + 1 == galleryTotal)) {
console.log("At last page, time to load");
var store = this.config.store;
store.nextPage({ addRecords: true });
}
}
I think I understand your issue. Assuming you've got 3 items and you're always viewing the middle one (as you move forward, item 0 gets destroyed and one item gets created). And assuming that each item has an id associated with its location in the list.
var current_item = Ext.getCmp('carousel_name').getActiveItem().getId();
current_item = Number(current_item.replace('item', ''));
//Objects to create
var next_item = current_item + 1;
var previous_item = current_item - 1;
//Objects to destroy
var next2_item = current_item + 2;
var previous2_item = current_item - 2;
//Create items
var createItem = function(item_location, type){
var carousel_item = create_content(item_location);
if(type == 'next'){
Ext.getCmp('carousel_name').add(carousel_item);
}else if(type == 'previous'){
Ext.getCmp('carousel_name').insert(0, carousel_item);
Ext.getCmp('carousel_name').setActiveItem(1);
}
}
createItem(next_item,'next');
createItem(previous_item,'previous');
//Destroy items
if(Ext.getCmp('item'+previous2_item)){
Ext.getCmp('carousel_name').getItems().items[0].destroy();//This is a hack, for some reason with the above commented out line, the item was getting destroyed but wasn't being removed from carousel_name
}
if(Ext.getCmp('item'+next2_item)){
Ext.getCmp('carousel_name').getItems().items[Ext.getCmp('carousel_name').getMaxItemIndex()].destroy();//This is a hack, consistency with previous destroy (above)
}

Ajax update pannel problem

I have a dropdown and 2 listboxs in a updated panel and a save button on the page. When the page loads I load one of the list boxes with data related to the selected dropdown item. When the user selects a different item in the drop down I do a postback and reload the listbox with data related to the selected item. When the user clicks save on the page the listbox.Items are the orginal items loaded with the first page load and the items that are showing on the page.
Any ideas how to fix this?
Make sure you dont bind the data on every postback. Use Page.IsPostback to check this.
To fix this problem I had to update the viewstate from the client side. Below is the javascript function I called once the postback of the update panel is completed:
function UpdateStateforList(list){
var i;
var state = "1";
for(i = 0; i < list.options.length; i++){
state += "|" + list.options[i].text + "|" + list.options[i].value;
}
eval("document.forms[0]." + list.id + "_State.value = state");
}

Dom4j detach node, Jython

I am using Dom4j to detach a node, like below:
<div name="divName">
Some Text Here
<span>Some Text Here</span>
</div>
I am selecting the div node by name and then using the detach method to remove it:
xpathValue = "//*[contains(#name, 'divName')]"
xpath = dom.createXPath(xpathValue)
if xpath != None:
nodes = xpath.selectNodes(dom)
if len(nodes) > 0:
for node in nodes:
node.detach()
This seems to remove the div fine, I noticed that it also removes elements and text within that div also. What I am looking to achive is removing the div without removing the elements and text inside the div, resulting in this:
Some Text Here
<span>Some Text Here</span>
Is it possible to achive this with dom4j? If not any suggestions on how to go about this?
Cheers
Eef
Update:
#alamar
I have achived what I wanted by taking your code and editing it a little and this is what I have come up with:
xpathValue = "//*[contains(#name, 'divName')]"
xpath = dom.createXPath(xpathValue)
if xpath != None:
nodes = xpath.selectNodes(dom)
if len(nodes) > 0:
for node in nodes:
parent = node.getParent()
nodeContents = node.content()
if len(nodeContents) > 0:
for subNode in nodeContents:
parent.add(subNode.clone().detach())
node.detach()
This seems to work, but adds the nodes to the end of the parent node in the below situation:
<div name="parent">
<div name="divName">
Some Text Here
<span>Some Text Here</span>
</div>
<div name="keep"></div>
</div>
The result is this:
<div name="parent">
<div name="keep"></div>
Some Text Here
<span>Some Text Here</span>
</div>
I am trying to figure out how to get the contents of the removed node to stay in its original position, before thed div named "keep", instead of being added after the div with the name "keep". I have tried a few thing but can not seem achive this, could anyone help?
Eef
If you want to keep the order of elements, you should really ask parent for its content().
In that content (which is a List backed by parent element) collection, you should find your div and replace it with that div's content().
I don't remember idiomatic way to do that in python, frankly.
probably
if xpath != None:
nodes = xpath.selectNodes(dom)
if len(nodes) > 0:
for node in nodes:
parent = node.getParent()
index = parent.indexOf(node)
siblings = parent.content()
nodeContents = node.content()
if len(nodeContents) > 0:
for subNode in nodeContents:
siblings.add(subNode.clone().detach(), index++)
node.detach()
Try:
if xpath != None:
nodes = xpath.selectNodes(dom)
if len(nodes) > 0:
for div in nodes:
parent = div.getParent()
div.detach()
for(child in node.content())
child.detach()
parent.add(child)
I believe it would do the trick.
I.e. after detaching every div, you should reattach every div's child into div's parent.
i had a similar problem and solved it with the following function (works fine for me)
What is it doing: it will simply remove that parent tag and includes every element and node inside the element to the parent at that position.
private void _replaceTagByContent(Element element) {
Element parent = element.getParent();
List elements = parent.elements();
int insertPosition = elements.indexOf(element);
// add them all to the parent again
for (int i = 0, size = elements.size(); i < size; i++) {
Node node = (Node) elements.get(i);
if (i == insertPosition) {
// if we are here, then this has to be an element, since
// wo do only replace elements ...
for (int j = element.nodeCount() - 1; j >= 0; j--) {
Node theNode = element.node(j);
theNode.detach();
elements.add(i, theNode);
}
// finally remove this node
elements.remove(node);
}
}
}
enjoy cnsntrk

Resources